Add: version

main
git 2023-04-09 22:45:28 +08:00
parent d6314954cc
commit d426f82165
Signed by: git
GPG Key ID: 3F65EFFA44207ADD
1 changed files with 32 additions and 0 deletions

32
version/version.go Normal file
View File

@ -0,0 +1,32 @@
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)
}