-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
57 lines (47 loc) · 1.19 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
53
54
55
56
57
//go:generate go-build-info -p treksum -o build_info.go
package treksum
import (
"fmt"
"runtime"
"strings"
)
const (
Version = "v0.0.5"
VersionTag = "dev"
sep = "-"
)
var AppInfo appInfo
type appInfo struct {
App string `json:"app"`
VersionInfo VersionInfo `json:"version_info"`
}
func (this *appInfo) String() string {
return fmt.Sprintf("%s %s", this.App, this.VersionInfo.VersionString)
}
type VersionInfo struct {
Version string `json:"version"`
VersionTag string `json:"tag"`
VersionString string `json:"version_string"`
Revision string `json:"revision"`
Branch string `json:"branch"`
BuildUser string `json:"build_user"`
BuildDate string `json:"build_date"`
GoVersion string `json:"go_version"`
}
func init() {
AppInfo = appInfo{
VersionInfo: VersionInfo{
Version: Version,
VersionTag: VersionTag,
VersionString: GetVersionString(),
Revision: BuildRevision,
Branch: BuildBranch,
BuildUser: BuildUser,
BuildDate: BuildDate,
GoVersion: runtime.Version(),
},
}
}
func GetVersionString() string {
return strings.TrimRight(strings.Join([]string{Version, VersionTag}, sep), " "+sep)
}