DEV Community

Clavin June
Clavin June

Posted on • Originally published at clavinjune.dev on

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

Discussion (0)