Using the -ldflags parameter can help set variable values at compile time.
Using the example provided here:
- Running make buildwill create abuildexecutable. Running it will result in:
$> ./build
no version (Mon YYYY)
$>- Running make build_versionwill use theversionanddatevariables defined in the makefile and using the-ldflagsoption to set the values ofversionanddateinmain.go.
$> ./build
0.0.1 (Aug 2017)
$>