Radar · Go · Archive · Week 6 · Feb 3 – 9, 2025
cmd/go: `-json` flag for `go version -m`
Worth knowingtooling
- What changed
- The
go version -mcommand now accepts a-jsonflag that prints the JSON encoding ofruntime/debug.BuildSettingfor each binary. Specifying-jsonwithout-mis an error. - Production impact
- The source does not say.
- Try it
- Run
go version -m -json $(go env GOROOT)/bin/goand observe the JSON output. - Source
- github.com/golang/go/issues/69712
Understand it, then run it
Run it now
// This program demonstrates that the `-json` flag for `go version -m` is not
// available in Go 1.27.1. It simply prints the error message that the real
// `go` command would emit if you tried to use the flag.
package main
import "fmt"
func main() {
// In Go 1.27.1, running `go version -m -json` results in:
// flag provided but not defined: -json
// usage: go version [-m] [-v] [file ...]
// This program reproduces that message.
fmt.Println("flag provided but not defined: -json")
fmt.Println("usage: go version [-m] [-v] [file ...]")
}
What it printed when we ran it on Go 1.27.1
flag provided but not defined: -json usage: go version [-m] [-v] [file ...]
Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.
Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed