-
Notifications
You must be signed in to change notification settings - Fork 1
/
version.go
54 lines (49 loc) · 1.42 KB
/
version.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package version
import (
"fmt"
"runtime"
"strings"
)
// Info is heavily informed by the Kubernetes Versioning System.
type Info struct {
Major string `json:"major"`
Minor string `json:"minor"`
FixVr string `json:"fixvr"`
GitVersion string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
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 {
return info.GitVersion
}
// 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 ./base.go
// If major and minor are not individually set with ldflags, we can
// separate the .version file as passed with an ldflag
if fsMajor == "" && fsMinor == "" {
if fsVersion != "" {
fsVersions := strings.Split(fsVersion, ".")
fsMajor = fsVersions[0]
fsMinor = fsVersions[1]
fsFixVr = fsVersions[2]
}
}
return Info{
Major: fsMajor,
Minor: fsMinor,
FixVr: fsFixVr,
GitVersion: gitVersion,
GitCommit: sha1ver,
BuildDate: buildDate,
GoVersion: runtime.Version(),
Compiler: runtime.Compiler,
Platform: fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH),
}
}