This is a quick demo of how to set information about your current git repository and build time as variables within your Go binary.
- Gather information and set
-ldflags
during build in theMakefile
- Define variables in your Go code that will be set during build
This example sets 3 variables:
- Timestamp of when the build happens
- The current git commit hash, including a
✗-
prefix if the working directory is dirty - The current git branch
$ make
$ bin/vars