-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.go
41 lines (33 loc) · 1.09 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
package vanity
import "fmt"
// Version component constants for the current build.
const (
VersionMajor = 1
VersionMinor = 1
VersionPatch = 0
VersionReleaseLevel = ""
VersionReleaseNumber = 2
)
// Set the GitVersion via -ldflags="-X 'go.rtnl.ai/vanity.GitVersion=$(git rev-parse --short HEAD)'"
var GitVersion string
// Set the BuildDate via -ldflags="-X go.rtnl.ai/vanity.BuildDate=YYYY-MM-DD"
var BuildDate string
// Version returns the semantic version for the current build.
func Version() string {
versionCore := fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
if VersionReleaseLevel != "" {
if VersionReleaseNumber > 0 {
versionCore = fmt.Sprintf("%s-%s.%d", versionCore, VersionReleaseLevel, VersionReleaseNumber)
} else {
versionCore = fmt.Sprintf("%s-%s", versionCore, VersionReleaseLevel)
}
}
if GitVersion != "" {
if BuildDate != "" {
versionCore = fmt.Sprintf("%s (revision %s built on %s)", versionCore, GitVersion, BuildDate)
} else {
versionCore = fmt.Sprintf("%s (%s)", versionCore, GitVersion)
}
}
return versionCore
}