№ 11467 В разделе
Programming
от December 12th, 2021,
В подшивках: Go
Useful to set version or build number. Also you can use embed.
Code:
package main import "fmt" var MyVariable = "jopa" func main() { fmt.Printf("%s\n", MyVariable) }
Build script:
#!/usr/bin/bash ENVVAR="jopa i piska" LDFLAGS=( "-X 'main.MyVariable=${ENVVAR}'" ) go build -o testvar -ldflags="${LDFLAGS[*]}" main.go ./testvar rm -f ./testvar
Output:
$ ./build.sh jopa i piska
Fortune cookie: Handel's Proverb: You can't produce a baby in one month by impregnating 9 women!
Leave a Reply