This is a creation in Article, where the information may have evolved or changed.
Http://wendal.net/2014/04/02.html
Reference article: http://stackoverflow.com/questions/11354518/golang-application-auto-build-versioning
Yesterday in the query how to generate a small volume of the Golang program, inadvertently found this article.
For fixed code, and fixed version of Golang, the following command always gets the exact same program
go build
Sometimes you need to mark every compilation, or it's really messy.
Golang Code for Demo
PackageMainvar_version_= "Unknown"Func main() { Print("Http_su ver=" +_version_+ "\ n")}
Compile, add the required version number information, rather than directly to change the source of Main.go
export TAG = v1 b 50 go build - ldflags "-X main._version_ ' $TAG '"
Operation Result:
>Go Build> ./Demohttp_su ver=Unknown> ExportTAG=v.1.b. ->Go Build-Ldflags"-X main._version_ ' $TAG '"> ./Demohttp_su ver=v.1.b. -
As you can see, the version number changes depending on the compilation parameters. The key point is that it must be $package. $varName
This demo was tested and passed under Linux/macos/windows/arm.