-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathversion.go
60 lines (51 loc) · 1.27 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
58
59
60
package go_librespot
import (
"fmt"
"runtime"
"runtime/debug"
"strings"
)
var commit, version string
// Extract and return the commit hash stored in the binary, if available.
func commitHash() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return ""
}
func VersionNumberString() string {
if len(version) > 0 {
return strings.TrimPrefix(version, "v")
} else if len(commit) >= 8 {
return commit[:8]
} else if commit := commitHash(); len(commit) >= 8 {
return commit[:8]
} else {
return "dev"
}
}
func SpotifyLikeClientVersion() string {
if len(version) > 0 {
if len(commit) >= 8 {
return fmt.Sprintf("%s.g%s", version, commit[:8])
} else if commit := commitHash(); len(commit) >= 8 {
return fmt.Sprintf("%s.g%s", version, commit[:8])
} else {
return version
}
}
return "0.0.0"
}
func VersionString() string {
return fmt.Sprintf("go-librespot %s", VersionNumberString())
}
func SystemInfoString() string {
return fmt.Sprintf("%s; Go %s (%s %s)", VersionString(), runtime.Version(), runtime.GOOS, runtime.GOARCH)
}
func UserAgent() string {
return fmt.Sprintf("go-librespot/%s Go/%s", VersionNumberString(), runtime.Version())
}