diff --git a/main.go b/main.go index dfdfeabd..5cac80ad 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,11 @@ import ( "github.com/penggy/service" ) +var ( + gitCommitCode string + buildDateTime string +) + type program struct { httpPort int httpServer *http.Server @@ -128,13 +133,20 @@ func main() { flag.StringVar(&utils.FlagVarConfFile, "config", "", "configure file path") flag.Parse() tail := flag.Args() + // log log.SetPrefix("[EasyDarwin] ") log.SetFlags(log.Lshortfile | log.LstdFlags) if !utils.Debug { log.Println("log files -->", utils.LogDir()) + log.Printf("git commit code:%s", gitCommitCode) + log.Printf("build date:%s", buildDateTime) log.SetOutput(utils.GetLogWriter()) } + log.Printf("git commit code:%s", gitCommitCode) + log.Printf("build date:%s", buildDateTime) + routers.BuildVersion = fmt.Sprintf("%s.%s", routers.BuildVersion, gitCommitCode) + routers.BuildDateTime = buildDateTime sec := utils.Conf().Section("service") svcConfig := &service.Config{ diff --git a/package.json b/package.json index 8c5a59fd..d25b3e1f 100644 --- a/package.json +++ b/package.json @@ -7,9 +7,9 @@ "build:ico": "rsrc -arch amd64 -ico ed.ico -o EasyDarwin_windows.syso", "build:www": "cd web_src && npm run build && cd .. && apidoc -i routers -o www/apidoc", "build:doc": "apidoc -i routers -o www/apidoc", - "build:win": "go build -tags release -ldflags \"-s -w\" -o EasyDarwin.exe", - "build:lin": "go build -tags release -ldflags \"-s -w\" -o easydarwin", - "build:dev": "go build -o EasyDarwin.exe", + "build:win": "go build -tags release -ldflags \"-X 'main.buildDateTime=$(date '+%Y-%m-%d %H:%M:%S')' -X 'main.gitCommitCode=$(git rev-list --full-history --all --abbrev-commit --max-count 1)' -s -w\" -o EasyDarwin.exe", + "build:lin": "go build -tags release -ldflags \"-X 'main.buildDateTime=$(date '+%Y-%m-%d %H:%M:%S')' -X 'main.gitCommitCode=$(git rev-list --full-history --all --abbrev-commit --max-count 1)' -s -w\" -o easydarwin", + "build:dev": "go build -ldflags \"-X 'main.buildDateTime=$(date '+%Y-%m-%d %H:%M:%S')' -X 'main.gitCommitCode=$(git rev-list --full-history --all --abbrev-commit --max-count 1)'\" -o EasyDarwin.exe", "dev": "gobuild -o EasyDarwin.exe", "dev:lin": "gobuild -o easydarwin", "dev:www": "cd web_src && npm run start", @@ -65,5 +65,5 @@ ] } } - ] + ] } diff --git a/routers/sys.go b/routers/sys.go index 2a81f6da..0792e15a 100644 --- a/routers/sys.go +++ b/routers/sys.go @@ -113,7 +113,7 @@ func (h *APIHandler) GetServerInfo(c *gin.Context) { "InterfaceVersion": "V1", "RunningTime": utils.UpTimeString(), "StartUpTime": utils.DateTime(utils.StartTime), - "Server": fmt.Sprintf("%s/%s (Platform/%s;)", "EasyDarwin", BuildVersion, strings.Title(runtime.GOOS)), + "Server": fmt.Sprintf("%s/%s,%s (Platform/%s;)", "EasyDarwin", BuildDateTime, BuildVersion, strings.Title(runtime.GOOS)), "memData": memData, "cpuData": cpuData, "pusherData": pusherData, diff --git a/routers/types.go b/routers/types.go index bb2d2e38..7f2b0aa5 100644 --- a/routers/types.go +++ b/routers/types.go @@ -2,9 +2,8 @@ package routers import "github.com/penggy/EasyGoLib/utils" -const ( - BuildVersion = "v8.1" -) +var BuildVersion = "v8.1" +var BuildDateTime = "" type PercentData struct { Time utils.DateTime `json:"time"`