代码拉取完成,页面将自动刷新
package version
import (
"encoding/json"
"fmt"
"github.com/gosuri/uitable"
"runtime"
)
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 {
treeStateFlag := "*"
if info.GitTreeState != "dirty" {
treeStateFlag = ""
}
return fmt.Sprintf("%s-%s%s %s %s-%s %s", info.GitVersion, treeStateFlag, info.GitCommit, info.BuildDate, info.GoVersion, info.Compiler, info.Platform)
}
// 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),
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。