feat: add build revision and build time

This commit is contained in:
LinkinStar 2022-10-18 12:19:07 +08:00
parent 2042200f27
commit c558219628
3 changed files with 7 additions and 2 deletions

View File

@ -6,7 +6,8 @@ DIR_SRC=./cmd/answer
DOCKER_CMD=docker
GO_ENV=CGO_ENABLED=0
GO_FLAGS=-ldflags="-X main.Version=$(VERSION) -X 'main.Time=`date`' -extldflags -static"
Revision=$(shell git rev-parse --short HEAD)
GO_FLAGS=-ldflags="-X main.Version=$(VERSION) -X main.Revision=$(Revision) -X 'main.Time=`date`' -extldflags -static"
GO=$(GO_ENV) $(shell which go)
build:

View File

@ -18,7 +18,7 @@ var (
)
func init() {
rootCmd.Version = Version
rootCmd.Version = fmt.Sprintf("%s\nrevision: %s\nbuild time: %s", Version, Revision, Time)
initCmd.Flags().StringVarP(&dataDirPath, "data-path", "C", "/data/", "data path, eg: -C ./data/")

View File

@ -20,6 +20,10 @@ var (
Name = "answer"
// Version is the version of the project
Version = "development"
// Revision is the git short commit revision number
Revision = ""
// Time is the build time of the project
Time = ""
// log level
logLevel = os.Getenv("LOG_LEVEL")
// log path