From d426f821656426a3c7c1c8bea302bddcc7aace3e Mon Sep 17 00:00:00 2001 From: joelei Date: Sun, 9 Apr 2023 22:45:28 +0800 Subject: [PATCH] Add: version --- version/version.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 version/version.go diff --git a/version/version.go b/version/version.go new file mode 100644 index 0000000..7a4694e --- /dev/null +++ b/version/version.go @@ -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) +}