Using the -ldflags
parameter can help set variable values at compile time.
Using the example provided here:
- Running
make build
will create abuild
executable. Running it will result in:
$> ./build
no version (Mon YYYY)
$>
- Running
make build_version
will use theversion
anddate
variables defined in the makefile and using the-ldflags
option to set the values ofversion
anddate
inmain.go
.
$> ./build
0.0.1 (Aug 2017)
$>