Skip to content

Instantly share code, notes, and snippets.

@ggzeng
Last active October 21, 2019 16:56
Show Gist options
  • Save ggzeng/64a0f1ce9d70c066cd7394d5fd8fd667 to your computer and use it in GitHub Desktop.
Save ggzeng/64a0f1ce9d70c066cd7394d5fd8fd667 to your computer and use it in GitHub Desktop.
在build编译的时候初始化包中的变量
package main
import "fmt"
var (
VERSION string
BUILD_TIME string
GO_VERSION string
)
func main() {
fmt.Printf("%s\n%s\n%s\n", VERSION, BUILD_TIME, GO_VERSION)
}
// go build -ldflags "-X main.VERSION=1.0.0 -X 'main.BUILD_TIME=`date -u +.%Y%m%d.%H%M%S`' -X 'main.GO_VERSION=`go version`'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment