Skip to content

Instantly share code, notes, and snippets.

@serverhorror
Last active July 26, 2019 13:59
Show Gist options
  • Save serverhorror/ca7fd661eca87241153d2ef6d2052438 to your computer and use it in GitHub Desktop.
Save serverhorror/ca7fd661eca87241153d2ef6d2052438 to your computer and use it in GitHub Desktop.
How to embed information at build time
# PowerShell
go run `
  -ldflags="
    -X 'main.version=$(git name-rev --tags --name-only --always --no-undefined $(git rev-parse HEAD))' `
    -X 'main.commitInfo=$(if (git status --porcelain=v2 --untracked-files=no) {Write-Output "*"} else {Write-Output "clean"})' `
    -X 'main.buildTime=tomorrow.afternoon'" `
  .\playground\versionInject\main.go
# sh
go run \
  -ldflags=\
    -X 'main.version=$(git name-rev --tags --name-only --always --no-undefined $(git rev-parse HEAD))' \
    -X 'main.commitInfo=$(git status --porcelain=v2 --untracked-files=no)' \
    -X 'main.buildTime=tomorrow.afternoon'" \
  .\playground\versionInject\main.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment