|
|
@@ -0,0 +1,41 @@
|
|
|
+package ver
|
|
|
+
|
|
|
+/*
|
|
|
+ Support edit version relative information dynamically.
|
|
|
+
|
|
|
+ 1. When you build your main project with:
|
|
|
+
|
|
|
+`go build -ldflags="-w -X 'git.wenlab.co/joe/kettle/ver.Version=$(VER)' \
|
|
|
+ -X 'git.wenlab.co/joe/kettle/ver.Date=$(shell date +"%Y-%m-%dT%H:%M:%S")' \
|
|
|
+ -X 'git.wenlab.co/joe/kettle/ver.Branch=$(shell git branch --show-current)' \
|
|
|
+ -X 'git.wenlab.co/joe/kettle/ver.Commit=$(shell git rev-parse HEAD)' \
|
|
|
+ -X 'git.wenlab.co/joe/kettle/ver.GoVersion=$(shell go version)' \
|
|
|
+ -X 'git.wenlab.co/joe/kettle/ver.Tag=$(shell git describe --tags --always --dirty)'"`
|
|
|
+
|
|
|
+ 2. At starting of your project:
|
|
|
+
|
|
|
+ ver.PrintVersion()
|
|
|
+
|
|
|
+*/
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+)
|
|
|
+
|
|
|
+var (
|
|
|
+ Version = "v0.0.1"
|
|
|
+ Date = "2021-01-03"
|
|
|
+ Branch = "master"
|
|
|
+ Commit = "commitid"
|
|
|
+ GoVersion = "1.17"
|
|
|
+ Tag = "tag"
|
|
|
+)
|
|
|
+
|
|
|
+func Print() {
|
|
|
+ fmt.Printf(`Version: %v
|
|
|
+BuildDate: %v
|
|
|
+Branch: %v
|
|
|
+CommitID: %v
|
|
|
+Go: %v
|
|
|
+Tag: %v
|
|
|
+`, Version, Date, Branch, Commit, GoVersion, Tag)
|
|
|
+}
|