-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.go
51 lines (40 loc) · 900 Bytes
/
build.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
package main
import "encoding/json"
var gitTag string // populated with -ldflags
var gitBranch string // populated with -ldflags
var gitHash string // populated with -ldflags
var gitDirty string // populated with -ldflags
type BuildInfo struct {
GitTag string `json:"gitTag"`
GitBranch string `json:"gitBranch"`
GitHash string `json:"gitHash"`
GitDirty bool `json:"gitDirty"`
}
func (b *BuildInfo) toJson() string {
jsonBytes, err := json.Marshal(b)
if err != nil {
return ""
}
return string(jsonBytes)
}
func GetBuildInfo() BuildInfo {
info := BuildInfo{
GitTag: "unknown",
GitBranch: "unknown",
GitHash: "unknown",
GitDirty: false,
}
if gitTag != "" {
info.GitTag = gitTag
}
if gitBranch != "" {
info.GitBranch = gitBranch
}
if gitHash != "" {
info.GitHash = gitHash
}
if gitDirty == "true" {
info.GitDirty = true
}
return info
}