-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmodel.go
35 lines (33 loc) · 850 Bytes
/
model.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
package useragent
import (
"strings"
)
// detectModel some properties of the model from the given section.
func (p *UserAgent) detectModel(s section) {
if !p.mobile {
return
}
if p.platform == "iPhone" || p.platform == "iPad" {
p.model = p.platform
return
}
// Android model
if s.name == "Mozilla" && p.platform == "Linux" && len(s.comment) > 2 {
mostAndroidModel := s.comment[2]
if strings.Contains(mostAndroidModel, "Android") || strings.Contains(mostAndroidModel, "Linux") {
mostAndroidModel = s.comment[len(s.comment)-1]
}
tmp := strings.Split(mostAndroidModel, "Build")
if len(tmp) > 0 {
p.model = strings.Trim(tmp[0], " ")
return
}
}
// traverse all item
for _, v := range s.comment {
if strings.Contains(v, "Build") {
tmp := strings.Split(v, "Build")
p.model = strings.Trim(tmp[0], " ")
}
}
}