-
Notifications
You must be signed in to change notification settings - Fork 2
/
version.go
53 lines (45 loc) · 808 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
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"runtime/debug"
)
const unknown = "unknown"
var (
version = unknown
commit = unknown
date = unknown
)
func Commit() string {
if commit == unknown {
if val, ok := getBuildInfo("vcs.revision"); ok {
commit = val
}
if val, ok := getBuildInfo("vcs.modified"); ok {
if val == "true" {
commit = fmt.Sprintf("%s-ditry", commit)
}
}
}
return commit
}
func Timestamp() string {
if date == unknown {
if val, ok := getBuildInfo("vcs.time"); ok {
date = val
}
}
return date
}
func Version() string {
return version
}
func getBuildInfo(key string) (string, bool) {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == key {
return setting.Value, true
}
}
}
return "", false
}