1 Star 0 Fork 0

天雨流芳 / go-micro-framework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
version.go 2.31 KB
一键复制 编辑 原始数据 按行查看 历史
天雨流芳 提交于 2024-03-19 15:24 . 增加通用文件
// Package version supplies version information collected at build time to
// apimachinery components.
package version
import (
"fmt"
"gitee.com/tylf2018/go-micro-framework/pkg/common/json"
"runtime"
"github.com/gosuri/uitable"
)
var (
// GitVersion is semantic version.
GitVersion = "v0.0.0-master+$Format:%h$"
// BuildDate in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ').
BuildDate = "1970-01-01T00:00:00Z"
// GitCommit sha1 from git, output of $(git rev-parse HEAD).
GitCommit = "$Format:%H$"
// GitTreeState state of git tree, either "clean" or "dirty".
GitTreeState = ""
)
// Info contains versioning information.
type Info struct {
GitVersion string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
GitTreeState string `json:"gitTreeState"`
BuildDate string `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
}
// String returns info as a human-friendly version string.
func (info Info) String() string {
if s, err := info.Text(); err == nil {
return string(s)
}
return info.GitVersion
}
// ToJSON returns the JSON string of version information.
func (info Info) ToJSON() string {
s, _ := json.Marshal(info)
return string(s)
}
// Text encodes the version information into UTF-8-encoded text and
// returns the result.
func (info Info) Text() ([]byte, error) {
table := uitable.New()
table.RightAlign(0)
table.MaxColWidth = 80
table.Separator = " "
table.AddRow("gitVersion:", info.GitVersion)
table.AddRow("gitCommit:", info.GitCommit)
table.AddRow("gitTreeState:", info.GitTreeState)
table.AddRow("buildDate:", info.BuildDate)
table.AddRow("goVersion:", info.GoVersion)
table.AddRow("compiler:", info.Compiler)
table.AddRow("platform:", info.Platform)
return table.Bytes(), nil
}
// Get returns the overall codebase version. It's for detecting
// what code a binary was built from.
func Get() Info {
// These variables typically come from -ldflags settings and in
// their absence fallback to the settings in pkg/version/base.go
return Info{
GitVersion: GitVersion,
GitCommit: GitCommit,
GitTreeState: GitTreeState,
BuildDate: BuildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}
1
https://gitee.com/tylf2018/go-micro-framework.git
git@gitee.com:tylf2018/go-micro-framework.git
tylf2018
go-micro-framework
go-micro-framework
a23f37e8bd2b

搜索帮助