]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: output missing GoDebug entries
authorIan Alexander <jitsu@google.com>
Thu, 25 Sep 2025 15:07:17 +0000 (11:07 -0400)
committerIan Alexander <jitsu@google.com>
Sat, 8 Nov 2025 12:25:35 +0000 (04:25 -0800)
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/modcmd/edit.go
src/cmd/go/testdata/script/mod_edit_issue75105.txt [new file with mode: 0644]

index 4cd8d875012c3c06b2fa5e886c15d9180581d095..69ebb14813bea5b3654ad22074adae03b1c2ed60 100644 (file)
@@ -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 (file)
index 0000000..8984dae
--- /dev/null
@@ -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
+}