Golang Inject Build Time Variable

sunday-snippet · May 1, 2022 · ~1 min
Sunday Snippet #15 golang inject build time variable
Sunday Snippet #15 golang inject build time variable
1
2
3
4
5
6
7
8
9
package main

import . "fmt"

var foo = "not injected"

func main() {
	Println(foo)
}
1
2
3
4
$ go run main.go
not injected
$ go run -ldflags "-X main.foo=injected" main.go
injected
· · ·

Love This Content?

Any kind of supports is greatly appreciated! Kindly support me via Bitcoin, Ko-fi, Trakteer, or just continue to read another content. You can write a response via Webmention and let me know the URL via Telegraph.

Drop Your Comment Below