使用“ go build”命令在编译时使用shell变量值[重复]

This question already has an answer here:

I'm building Golang project on gitlab CI and I'd like to pass $CI_COMMIT_TAG value to compiler. With g++ it would be something like g++ -DCI_COMMIT_TAG=$CI_COMMIT_TAG .... Is there anything simillar for go build command?

</div>

main.go

package main

var YOUR_VARIABLE = ""

func main() {}

Shell command: go build -ldflags "-X main.YOUR_VARIABLE=$your_variable" main.go