Skip to content

Instantly share code, notes, and snippets.

@mhamrah
Created July 9, 2018 15:54
Show Gist options
  • Save mhamrah/b2b337c826763f6893d7e4d61b2bffe8 to your computer and use it in GitHub Desktop.
Save mhamrah/b2b337c826763f6893d7e4d61b2bffe8 to your computer and use it in GitHub Desktop.
Set go variable with LD
import (
"fmt"
)
// use ldflags to set this var at build time:
// go build -ldflags "-X main.version=$(git tag)"
// go build -ldflags "-X main.version=$(git rev-parse HEAD)"
var version string
func main() {
fmt.Printf("version: %v\n", version)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment