forked from mileusna/useragent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
version.go
65 lines (58 loc) · 1.71 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
61
62
63
64
65
package useragent
import (
"fmt"
"strconv"
"strings"
)
type VersionNo struct {
Major int
Minor int
Patch int
}
func parseVersion(ver string, verno *VersionNo) {
var err error
parts := strings.Split(ver, ".")
if len(parts) > 0 {
if verno.Major, err = strconv.Atoi(parts[0]); err != nil {
return
}
}
if len(parts) > 1 {
if verno.Minor, err = strconv.Atoi(parts[1]); err != nil {
return
}
if len(parts) > 2 {
if verno.Patch, err = strconv.Atoi(parts[2]); err != nil {
return
}
}
}
}
// VersionNoShort return version string in format <Major>.<Minor>
func (ua UserAgent) VersionNoShort() string {
if ua.VersionNo.Major == 0 && ua.VersionNo.Minor == 0 && ua.VersionNo.Patch == 0 {
return ""
}
return fmt.Sprintf("%d.%d", ua.VersionNo.Major, ua.VersionNo.Minor)
}
// VersionNoFull returns version string in format <Major>.<Minor>.<Patch>
func (ua UserAgent) VersionNoFull() string {
if ua.VersionNo.Major == 0 && ua.VersionNo.Minor == 0 && ua.VersionNo.Patch == 0 {
return ""
}
return fmt.Sprintf("%d.%d.%d", ua.VersionNo.Major, ua.VersionNo.Minor, ua.VersionNo.Patch)
}
// OSVersionNoShort returns OS version string in format <Major>.<Minor>
func (ua UserAgent) OSVersionNoShort() string {
if ua.OSVersionNo.Major == 0 && ua.OSVersionNo.Minor == 0 && ua.OSVersionNo.Patch == 0 {
return ""
}
return fmt.Sprintf("%d.%d", ua.OSVersionNo.Major, ua.OSVersionNo.Minor)
}
// OSVersionNoFull returns OS version string in format <Major>.<Minor>.<Patch>
func (ua UserAgent) OSVersionNoFull() string {
if ua.OSVersionNo.Major == 0 && ua.OSVersionNo.Minor == 0 && ua.OSVersionNo.Patch == 0 {
return ""
}
return fmt.Sprintf("%d.%d.%d", ua.OSVersionNo.Major, ua.OSVersionNo.Minor, ua.OSVersionNo.Patch)
}