-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
52 lines (45 loc) · 1.04 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
package util
import (
"fmt"
"time"
)
const na string = "N/A"
// Version data
type Version struct {
Semantic string `json:"semantic"`
BuildDate string `json:"build-date"`
BuildTime *time.Time `json:"build-time"`
GitCommit string `json:"git-commit"`
GitBranch string `json:"git-branch"`
GitSummary string `json:"git-summary"`
}
// BuildString ...
func BuildString(version *Version) string {
if version.GitCommit == "" {
return na
}
return fmt.Sprintf("%s@%s, %s", version.GitBranch, version.GitCommit, version.BuildDate)
}
// GetBuildTime ...
func GetBuildTime(version *Version) *time.Time {
return version.BuildTime
}
// VersionString ...
func VersionString(version *Version) string {
if version.Semantic == "" {
return na
}
return version.Semantic
}
// VersionedBuildString ...
func VersionedBuildString(version *Version) string {
v := version.Semantic
gc := version.GitCommit
if v == "" {
v = na
}
if gc == "" {
gc = na
}
return fmt.Sprintf("%s, %s@%s, %s", v, version.GitBranch, gc, version.BuildDate)
}