forked from ipni/go-libipni
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.go
41 lines (35 loc) · 807 Bytes
/
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 libipni
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
)
//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
}
// Append the revision to the version.
for i := range bi.Settings {
if bi.Settings[i].Key == "vcs.revision" {
Revision = bi.Settings[i].Value
Version = Release + "-" + Revision
break
}
}
}