From b76103c08e72ac34db2092d2cf1a3c1ec6adf451 Mon Sep 17 00:00:00 2001 From: Ian Alexander Date: Thu, 25 Sep 2025 11:07:17 -0400 Subject: [PATCH] cmd/go: output missing GoDebug entries The `go help mod edit` command references the GoDebug struct, but `go mod edit -json` was not displaying them when appropriate. Fixes #75105 Change-Id: Iec987882941e01b0cf4d4fe31dda9e7a6e2dde87 Reviewed-on: https://go-review.googlesource.com/c/go/+/706757 LUCI-TryBot-Result: Go LUCI Reviewed-by: Michael Matloob Reviewed-by: Michael Matloob --- src/cmd/go/internal/modcmd/edit.go | 13 +++++-- .../testdata/script/mod_edit_issue75105.txt | 36 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/cmd/go/testdata/script/mod_edit_issue75105.txt diff --git a/src/cmd/go/internal/modcmd/edit.go b/src/cmd/go/internal/modcmd/edit.go index 4cd8d87501..69ebb14813 100644 --- a/src/cmd/go/internal/modcmd/edit.go +++ b/src/cmd/go/internal/modcmd/edit.go @@ -584,8 +584,9 @@ func flagDropIgnore(arg string) { // fileJSON is the -json output data structure. type fileJSON struct { Module editModuleJSON - Go string `json:",omitempty"` - Toolchain string `json:",omitempty"` + Go string `json:",omitempty"` + Toolchain string `json:",omitempty"` + GoDebug []debugJSON `json:",omitempty"` Require []requireJSON Exclude []module.Version Replace []replaceJSON @@ -599,6 +600,11 @@ type editModuleJSON struct { Deprecated string `json:",omitempty"` } +type debugJSON struct { + Key string + Value string +} + type requireJSON struct { Path string Version string `json:",omitempty"` @@ -657,6 +663,9 @@ func editPrintJSON(modFile *modfile.File) { for _, i := range modFile.Ignore { f.Ignore = append(f.Ignore, ignoreJSON{i.Path}) } + for _, d := range modFile.Godebug { + f.GoDebug = append(f.GoDebug, debugJSON{d.Key, d.Value}) + } data, err := json.MarshalIndent(&f, "", "\t") if err != nil { base.Fatalf("go: internal error: %v", err) diff --git a/src/cmd/go/testdata/script/mod_edit_issue75105.txt b/src/cmd/go/testdata/script/mod_edit_issue75105.txt new file mode 100644 index 0000000000..8984daee25 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_edit_issue75105.txt @@ -0,0 +1,36 @@ +env GO111MODULE=on + +go mod edit -godebug 'http2debug=2' +cmp go.mod go.mod.edit.want1 + +go mod edit -json +cmp stdout go.mod.edit.want2 +-- go.mod -- +module foo + +go 1.25.0 +-- go.mod.edit.want1 -- +module foo + +go 1.25.0 + +godebug http2debug=2 +-- go.mod.edit.want2 -- +{ + "Module": { + "Path": "foo" + }, + "Go": "1.25.0", + "GoDebug": [ + { + "Key": "http2debug", + "Value": "2" + } + ], + "Require": null, + "Exclude": null, + "Replace": null, + "Retract": null, + "Tool": null, + "Ignore": null +} -- 2.52.0