Skip to content

Instantly share code, notes, and snippets.

@peacefixation
Last active March 27, 2019 01:36
Show Gist options
  • Save peacefixation/a0f1c69ffa161118b211f71c334bd79e to your computer and use it in GitHub Desktop.
Save peacefixation/a0f1c69ffa161118b211f71c334bd79e to your computer and use it in GitHub Desktop.
Set version variable to Git hash at compile time
# https://goenning.net/2017/01/25/adding-custom-data-go-binaries-compile-time/
# https://golang.org/cmd/link/
GIT_HASH=$(shell git rev-parse HEAD)
FLAGS=-ldflags "-X main.version=$(GIT_HASH)"
build:
@go build $(FLAGS)
run:
@go run $(FLAGS) main.go
clean:
@rm app
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment