go podcast()

I talk about how I'm using the -LDFLAGS to inject variables value at build time so it's easier to grab the exact Git commit hash that user are using when reporting issues.

Show Notes

Usage of -ldflags:

go build -ldflags "-X main.varName=from_build" -o mycli

Inside your code:

var varName string

func main() {
  fmt.Println(varName) // prints "from_build"
}

Here's what I'm using for StaticBackend -v flag:

go build -ldflags \ 
"-X github.com/staticbackendhq/core/config.BuildTime=$(shell date +'%Y-%m-%d.%H:%M:%S') \
-X github.com/staticbackendhq/core/config.CommitHash=$(shell git log --pretty=format:'%h' -n 1) \
-X github.com/staticbackendhq/core/config.Version=$(shell git describe --tags)" \
-o staticbackend

Links:


Creators & Guests

Host
Dominic St-Pierre
Go system builder - entrepreneur. I've been writing software systems since 2001. I love SaaS, building since 2008.

What is go podcast()?

15 minutes news, tips, and tricks on the Go programming language.