-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuseragent.go
48 lines (42 loc) · 878 Bytes
/
useragent.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
package libportal
import (
ua "github.com./mileusna/useragent"
)
const (
uaMobile = "mobile"
uaTablet = "tablet"
uaDesktop = "desktop"
uaBot = "bot"
)
// UserAgent struct for parse useragent to internal struct
type UserAgent struct {
Type string `json:"type" bson:"type"`
Device string `json:"device" bson:"device"`
Name string `json:"name" bson:"name"`
OS string `json:"os" bson:"os"`
OSVersion string `json:"os_version" bson:"os_version"`
}
func NewUserAgent(useragent string) UserAgent {
var ua = ua.Parse(useragent)
var u = UserAgent{
OS: ua.OS,
OSVersion: ua.OSVersion,
Device: ua.Device,
Name: ua.Name,
}
var uaType string
if ua.Mobile {
uaType = uaMobile
}
if ua.Tablet {
uaType = uaTablet
}
if ua.Desktop {
uaType = uaDesktop
}
if ua.Bot {
uaType = uaBot
}
u.Type = uaType
return u
}