Listen "009: Set variables at build time with -LDFLAGS"
Episode Synopsis
Usage of -ldflags:go build -ldflags "-X main.varName=from_build" -o mycliInside your code:var varName stringfunc 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 staticbackendLinks:StaticBackend websiteStaticBackend GitHub repoBuild SaaS apps in Go (my online course and book)
More episodes of the podcast go podcast()
066: Xp, CI, CD with Jon Barber
04/11/2025
065: We're in the 3rd age of SaaS
29/10/2025
059: Is Go over with John Arundel
08/09/2025
ZARZA We are Zarza, the prestigious firm behind major projects in information technology.