I have a go program like this:
package main
import "fmt"
var version string
func main() {
fmt.Printf("Version %s
", version)
}
I would like to change the value of version at compile time, as demonstrated here, so I'm building it in this way (wtf.go is in src/wtf):
go build -ldflags "-X wtf/main.version=1.0.0.1234" wtf
go install wtf
But when I run, version is an empty string.
I have tried various casings of version, different variations of the package name and path. It seems that go build does not validate the package/variable name very much, as clearly bogus ones do not generate an error.
Is there a way I can find out what variable go is trying to modify so that I can troubleshoot this?
I'm using Go v 1.10.3 for Windows/amd64.