-
Notifications
You must be signed in to change notification settings - Fork 1
/
operatingsystem.go
101 lines (88 loc) · 1.75 KB
/
operatingsystem.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package uaparser
import (
"regexp"
)
// Operating System id's.
const (
WINDOWS = iota + 2 // 2
IOS // 3
MACOSX // 4
LINUX // 5
ANDROID // 6
WINDOWSPHONE // 7
CHROMEOS // 8
RIMOS // 9
)
var OperatingSystems = map[int64]string{
WINDOWS: "Windows",
IOS: "iOS",
MACOSX: "Mac OS X",
LINUX: "Linux",
ANDROID: "Android",
WINDOWSPHONE: "Windows Phone",
CHROMEOS: "Chrome OS",
RIMOS: "RIM OS",
}
var operatingSystems = []pattern{
// RIM OS
{
RIMOS,
[]string{"blackberry"},
[]string{},
nil,
},
// Windows
{
WINDOWS,
[]string{"windows"},
[]string{"windows phone"},
regexp.MustCompile(`windows nt[ ]?(\d+)\.(\d+)`),
},
// iOS
{
IOS,
[]string{"like mac os x"},
[]string{},
regexp.MustCompile(`os (\d+)(?:_(\d+))?`),
},
// Mac OS X
{
MACOSX,
[]string{"mac os x"},
[]string{"iphone", "ipad", "ipod"},
regexp.MustCompile(`mac os x (\d+)[_\.](\d+)`), // Safari uses '_', Firefox uses '.'.
},
// Linux
{
LINUX,
[]string{"linux"},
[]string{"android"},
nil,
},
// Android
{
ANDROID,
[]string{"android"},
[]string{"windows phone"}, // IE 12 on windows phone says it's android :(
regexp.MustCompile(`android (\d+)\.(\d+)`),
},
// Windows Phone
{
WINDOWSPHONE,
[]string{"windows phone"},
[]string{},
regexp.MustCompile(`phone (?:os )?(\d+)\.(\d+)`),
},
// Chrome OS
{
CHROMEOS,
[]string{"cros"},
[]string{},
nil,
},
}
// OperatingSystem will return the operating system id and version number.
// Returns 1,0 when nothing matched.
func OperatingSystem(userAgent string) (int64, int, int) {
return find(operatingSystems, userAgent)
}