pkg/version/version.go

33 lines
586 B
Go
Raw Normal View History

2023-04-09 14:45:28 +00:00
package version
import (
"fmt"
"os"
"runtime"
)
var (
// Version 版本号
Version = ""
// GitCommit CommitID
GitCommit = ""
// BuildTime 二进制构建事件
BuildTime = ""
// GoVersion Go 版本号
GoVersion = runtime.Version()
)
// GetVersion 获取版本信息
func GetVersion() string {
return fmt.Sprintf(
"Version : %s\nGitCommit: %s\nBuildTime: %s\nGoVersion: %s",
Version, GitCommit, BuildTime, GoVersion,
)
}
// ShowVersionAndExit 打印版本信息并退出
func ShowVersionAndExit() {
fmt.Printf("%s", GetVersion()) // nolint:forbidigo
os.Exit(0)
}