forked from kaorimatz/resque_exporter
-
Notifications
You must be signed in to change notification settings - Fork 4
/
version.go
46 lines (37 loc) · 872 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
package main
import (
"runtime/debug"
"time"
)
var (
tagVersion string
)
// Version represents version information.
type Version struct {
Development bool
SourceModified bool
SourceRevision string
SourceTime time.Time
Tag string
}
// GetInfo returns version information.
func GetInfo() Version {
buildInfo, _ := debug.ReadBuildInfo()
versionInfo := Version{Tag: tagVersion}
for _, setting := range buildInfo.Settings {
if setting.Key == "vcs.modified" && setting.Value == "true" {
versionInfo.SourceModified = true
}
if setting.Key == "vcs.revision" {
versionInfo.SourceRevision = setting.Value
}
if setting.Key == "vcs.time" {
versionInfo.SourceTime, _ = time.Parse(time.RFC3339, setting.Value)
}
}
if versionInfo.Tag == "" {
versionInfo.Development = true
versionInfo.Tag = "N/A"
}
return versionInfo
}