DEV Community

Clavin June
Clavin June

Posted on • Originally published at clavinjune.dev on

5 2

Golang Inject Build Time Variable

Sunday Snippet #15 golang inject build time variable

package main

import . "fmt"

var foo = "not injected"

func main() {
    Println(foo)
}
Enter fullscreen mode Exit fullscreen mode
$ go run main.go
not injected
$ go run -ldflags "-X main.foo=injected" main.go
injected
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay