-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
56 lines (43 loc) · 935 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
package main
import (
"fmt"
"strings"
)
// Set at build time
var version, commit, date string
type versionInfo struct {
VersionString string
CommitID string
Date string
}
func newVersionInfo() versionInfo {
refName := version
if len(refName) == 0 {
refName = "ver-unknown"
}
id := []rune(commit)
if len(id) > 10 {
id = id[:10]
}
return versionInfo{
VersionString: refName,
CommitID: string(id),
Date: date,
}
}
func (v versionInfo) HumanReadable() string {
if len(v.CommitID) == 0 {
return v.VersionString
}
return fmt.Sprintf("%s (commit %s, %s)", v.VersionString, v.CommitID, v.Date)
}
func (v versionInfo) HTTPUserAgent() string {
extra := []string{
v.VersionString,
}
if len(v.CommitID) > 0 {
extra = append(extra, "commit "+v.CommitID)
extra = append(extra, "date "+v.Date)
}
return fmt.Sprintf("Floaty by vshn.ch (%s)", strings.Join(extra, "; "))
}