-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.go
57 lines (47 loc) · 949 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
54
55
56
57
package main
import (
"fmt"
"runtime/debug"
)
// ServerVersion defines the server application version.
// Use -ldflags "-X main.ServerVersion=1.0.0" to override the version.
var ServerVersion string
func loadServerVersionFromBuildInfo() string {
info, ok := debug.ReadBuildInfo()
if !ok {
return ""
}
var (
commit string = "unknown"
dirty bool
)
for _, s := range info.Settings {
switch {
case s.Key == "vcs.revision":
commit = s.Value
if len(s.Value) > 10 {
commit = commit[:10]
}
case s.Key == "vcs.modified":
dirty = s.Value == "true"
}
}
if dirty {
commit += "-dirty"
}
s := fmt.Sprintf("sqlite-rest/%s (%s, commit/%s)", info.Main.Version, info.GoVersion, commit)
return s
}
func setServerVersion() {
if ServerVersion != "" {
return
}
if v := loadServerVersionFromBuildInfo(); v != "" {
ServerVersion = v
return
}
ServerVersion = "(devel)"
}
func init() {
setServerVersion()
}