-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
52 lines (45 loc) · 1 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 caskadht
import (
_ "embed"
"encoding/json"
"runtime/debug"
)
var (
// Release is the release version tag value, e.g. "v1.2.3"
Release string
// Revision is the git commit hash.
Revision string
// Version is the full version string: Release-Revision.
Version string
// Modified indicates if the source tree had local modifications.
Modified bool
)
//go:embed version.json
var versionJSON []byte
func init() {
// Read version from embedded JSON file.
var verMap map[string]string
json.Unmarshal(versionJSON, &verMap)
Release = verMap["version"]
// If running from a module, try to get the build info.
bi, ok := debug.ReadBuildInfo()
if !ok {
return
}
var found int
// Append the revision to the version.
for i := range bi.Settings {
switch bi.Settings[i].Key {
case "vcs.revision":
Revision = bi.Settings[i].Value
Version = Release + "-" + Revision
found++
case "vcs.modified":
Modified = bi.Settings[i].Value == "true"
found++
}
if found == 2 {
break
}
}
}