009: Set variables at build time with -LDFLAGS episode artwork

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)

Episode metadata supplied by the publisher feed · Published Aug 10, 2022

Embed this episode

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.

Distinct summary based on available episode metadata or transcript content.

Ready to play

009: Set variables at build time with -LDFLAGS

0:00 15:27

No transcript for this episode yet

We transcribe on demand. Request one and we'll notify you when it's ready — usually under 10 minutes.

No similar episodes found.

No similar podcasts found.

Frequently Asked Questions

How long is this episode of go podcast()?

This episode is 15 minutes long.

When was this go podcast() episode published?

This episode was published on August 10, 2022.

Can I download this go podcast() episode?

Yes. Use the download control on the episode player to save the publisher-provided media file.
URL copied to clipboard!