-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathversion.go
72 lines (64 loc) · 1.55 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"strings"
)
// Version stores the version tag - Should include leading 'v' - Update before tagging new versions.
//
var Version = "v0.11.3"
// BuildDate is optional and can be set using '-ldflags "-X 'main.BuildDate=..."'.
//
var BuildDate string
// GitSummary is optional and can be set using '-ldflags "-X 'main.GitSummary=..."'.
// Generally meant to contain the value of:
// git describe --tags --dirty --always
//
var GitSummary string
// BuildTool is optional and can be set using '-ldflags "-X 'main.BuildTool=..."'.
var BuildTool string
// versionString generates a version string from available vars.
// Variable names are compatible with govvv where applicable
//
func versionString() string {
version := strings.Builder{}
// Version
//
version.WriteString(Version)
// Extras
//
if len(BuildDate) > 0 || len(GitSummary) > 0 || len(BuildTool) > 0 {
if version.Len() > 0 {
version.WriteString(" ")
}
version.WriteString("(")
needsSpace := false
// Git Summary
//
if len(GitSummary) > 0 {
version.WriteString("build=")
version.WriteString(GitSummary)
needsSpace = true
}
// Build Date
//
if len(BuildDate) > 0 {
if needsSpace {
version.WriteString(" ")
}
version.WriteString("date=")
version.WriteString(BuildDate)
needsSpace = true
}
// Build Tool
//
if len(BuildTool) > 0 {
if needsSpace {
version.WriteString(" ")
}
version.WriteString("builder=")
version.WriteString(BuildTool)
// needsSpace = true
}
version.WriteString(")")
}
return version.String()
}