EPISODE · Aug 10, 2022 · 15 MIN
009: Set variables at build time with -LDFLAGS
from go podcast() · host Dominic St-Pierre
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)
Embed this episode
What this episode covers
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.
Ready to play
009: Set variables at build time with -LDFLAGS
No transcript for this episode yet
Similar Episodes
No similar episodes found.
Similar Podcasts
No similar podcasts found.