The following are a list of go lang tips I want to easily find in the future.
- How to Embedding Commit Ids in Go code from Red Hat
Using -ldflags
The most common way is by using a
string
variable, a value populated at build time via flags.For example:
var Commit string
go build -ldflags="-X main.Commit=$(git rev-parse HEAD)"
The disadvantage here is that you need to remember this syntax and run it every time you build your code. You can make this easier by using
Makefiles
to do that for you.