-
Notifications
You must be signed in to change notification settings - Fork 20
/
version.go
42 lines (34 loc) · 910 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
package config
import (
"runtime"
"strings"
)
const DevVersion = "dev"
var (
Version = DevVersion
UserAgent = UserAgentPrefix + SystemInfo + "/" + Version
UserAgentPrefix = "awl/"
SystemInfo = runtime.GOOS + "-" + runtime.GOARCH
)
// IsDevVersion
// Possible duplicate of *Config.DevMode()
// Based on build version (unchangeable after build, could be used only by developers)
func IsDevVersion() bool {
return Version == DevVersion
}
func VersionFromUserAgent(userAgent string) string {
i := strings.LastIndex(userAgent, "/")
if i == -1 || i == len(userAgent)-1 {
return ""
}
return userAgent[i+1:]
}
func SystemInfoFromUserAgent(userAgent string) (goos string, goarch string) {
userAgent = strings.TrimPrefix(userAgent, UserAgentPrefix)
systemInfo, _, ok := strings.Cut(userAgent, "/")
if !ok {
return
}
goos, goarch, _ = strings.Cut(systemInfo, "-")
return
}