mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-11 10:49:43 +08:00
feat: add GitCommit/GitBranch/BuildTime in version info
This commit is contained in:
@@ -1 +1 @@
|
||||
v5.0.0-beta-2503172016
|
||||
v5.0.0-beta-2503172040
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//go:embed VERSION
|
||||
var VERSION string
|
||||
|
||||
func init() {
|
||||
VERSION = strings.TrimSpace(VERSION)
|
||||
}
|
||||
31
internal/version/version.go
Normal file
31
internal/version/version.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package version
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
//go:embed VERSION
|
||||
var VERSION string
|
||||
|
||||
func init() {
|
||||
VERSION = strings.TrimSpace(VERSION)
|
||||
}
|
||||
|
||||
// 版本信息,在编译时通过 -ldflags 注入
|
||||
var (
|
||||
GitCommit = "unknown"
|
||||
GitBranch = "unknown"
|
||||
BuildTime = "unknown"
|
||||
)
|
||||
|
||||
func GetVersionInfo() string {
|
||||
commitID := GitCommit
|
||||
if len(commitID) > 8 {
|
||||
commitID = commitID[:8]
|
||||
}
|
||||
return fmt.Sprintf("%s (branch=%s, commit=%s, build=%s)",
|
||||
VERSION, GitBranch, commitID, BuildTime)
|
||||
}
|
||||
Reference in New Issue
Block a user