Compiling markup for the Golang program

Source: Internet
Author: User
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.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.