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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
This commit is contained in:
Ian Alexander 2025-09-25 11:07:17 -04:00
parent 47a63a331d
commit b76103c08e
2 changed files with 47 additions and 2 deletions

View 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)

View file

@ -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
}