Skip to content

cmd/go: mod edit -go is incompatible with env GOVERSION and the go/version package #77888

Description

@mvdan
$ go env GOVERSION
go1.26.0
$ go mod init test
go: creating new go.mod: module test
$ cat go.mod
module test

go 1.25.0
$ go mod edit -go=$(go env GOVERSION)
go mod: invalid -go option; expecting something like "-go 1.26.0"

go env GOVERSION is generally consistent with https://pkg.go.dev/go/version, which is nice, however the string used by go mod edit does not include the "go" prefix, making it incompatible.

It would be nice if this were made consistent. Internally, the toolchain already knows how to do this, I'm sure; it's just not very well exposed via the CLI.

I think the solution is for any CLI flag or argument which accepts a Go version to also accept the format with the "go" prefix, including go mod edit -go.

Note that the reverse issue also exists, i.e. go mod edit -json shows "Go": "1.25.0", which is again incompatible with https://pkg.go.dev/go/version. However, this is less of a pain point, at least for my scripting use cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.ToolProposalIssues describing a requested change to a Go tool or command-line program.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions