cmd/link: "-X main.version" when version has a value and is later used in a global struct literal doesn't work #34675
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Steps
main.go
,go build
and run it.go build -ldflags "-X main.version=foo"
If you change
var version = "dev"
tovar version string
, it works. It also works if you justfmt.Println("Version:", version)
without going through the struct.The documentation says:
Which doesn't suggest to me that this should somehow not work.
This will be a common scenario when using https://github.com/spf13/cobra which uses a global struct like that with a
Version
field, and is where I encountered this originally.main.go
What did you expect to see?
"Version: foo" when running
go build -ldflags "-X main.version=foo"
.What did you see instead?
"Version: dev" when running
go build -ldflags "-X main.version=foo"
.The text was updated successfully, but these errors were encountered: