forked from braatvedt/udger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.go
163 lines (146 loc) · 4.9 KB
/
types.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package udger
import (
"database/sql"
"net"
"regexp"
_ "github.com/mattn/go-sqlite3"
)
type Client interface {
// Lookup gathers information about the client using the provided user agent
Lookup(ua string) (*Info, error)
// LookupIP gathers information about the client using the provided IP
LookupIP(ip net.IP) (*IPInfo, error)
}
type udger struct {
db *sql.DB
rexBrowsers []rexData
rexDevices []rexData
rexOS []rexData
browserTypes map[int]string
browserOS map[int]int
Browsers map[int]Browser
OS map[int]OS
Devices map[int]Device
IP map[string]IP
IPClass map[int]IPClass
Crawler map[int]Crawler
CrawlerClass map[int]CrawlerClass
DataCenter map[int]DataCenter
DataCenterRange []DataCenterRange
DataCenterRange6 []DataCenterRange6
}
// Info is the struct returned by the Lookup(ua string) function, contains everything about the UA
type Info struct {
Browser Browser `json:"browser"`
OS OS `json:"os"`
Device Device `json:"device"`
}
// Browser contains information about the browser type, engine and off course it's name
type Browser struct {
Name string `json:"name"`
Family string `json:"family"`
Version string `json:"version"`
Engine string `json:"engine"`
typ int
Type string `json:"type"`
Company string `json:"company"`
Icon string `json:"icon"`
}
type rexData struct {
ID int
Regex string
RegexCompiled *regexp.Regexp
}
// OS contains all the information about the operating system
type OS struct {
Name string `json:"name"`
Family string `json:"family"`
Icon string `json:"icon"`
Company string `json:"company"`
}
// Device contains all the information about the device type
type Device struct {
Name string `json:"name"`
Icon string `json:"icon"`
}
type IPInfo struct {
IP IP `json:"ip"`
IPClass IPClass `json:"ip_class"`
Crawler Crawler `json:"crawler"`
CrawlerClass CrawlerClass `json:"crawler_class"`
DataCenter DataCenter `json:"data_center"`
DataCenterRange DataCenterRange `json:"data_center_range"`
DataCenterRange6 DataCenterRange6 `json:"data_center_range6"`
}
// Device contains all the information about the device type
type IP struct {
IP string `json:"ip"`
ClassID int `json:"class_id"`
CrawlerID int `json:"crawler_id"`
IPLastSeen string `json:"ip_last_seen"`
IPHostname string `json:"ip_hostname"`
IPCountry string `json:"ip_country"`
IPCity string `json:"ip_city"`
IPCountryCode string `json:"ip_country_code"`
}
type Crawler struct {
ID int `json:"id"`
UA string `json:"ua_string"`
Ver string `json:"ver"`
VerMajor string `json:"ver_major"`
ClassID int `json:"class_id"`
LastSeen string `json:"last_seen"`
RespectRobotstxt string `json:"respect_robotstxt"`
Family string `json:"family"`
FamilyCode string `json:"family_code"`
FamilyHomepage string `json:"family_homepage"`
FamilyIcon string `json:"family_icon"`
Vendor string `json:"vendor"`
VendorCode string `json:"vendor_code"`
VendorHomepage string `json:"vendor_homepage"`
Name string `json:"name"`
}
type IPClass struct {
ID int `json:"id"`
IPClassification string `json:"ip_classification"`
IPClassificationCode string `json:"ip_classification_code"`
}
type CrawlerClass struct {
ID int `json:"id"`
CrawlerClassification string `json:"crawler_classification"`
CrawlerClassificationCode string `json:"crawler_classification_code"`
}
type DataCenter struct {
ID int `json:"id"`
Name string `json:"name"`
NameCode string `json:"name_code"`
Homepage string `json:"homepage"`
}
type DataCenterRange struct {
DatacenterID int `json:"datacenter_id"`
IPFrom string `json:"ip_from"`
IPTo string `json:"ip_to"`
IPLongFrom int `json:"iplong_from"`
IPLongTo int `json:"iplong_to"`
}
type DataCenterRange6 struct {
DatacenterID int `json:"datacenter_id"`
IPFrom string `json:"ip_from"`
IPTo string `json:"ip_to"`
IPLongFrom0 int `json:"iplong_from0"`
IPLongFrom1 int `json:"iplong_from1"`
IPLongFrom2 int `json:"iplong_from2"`
IPLongFrom3 int `json:"iplong_from3"`
IPLongFrom4 int `json:"iplong_from4"`
IPLongFrom5 int `json:"iplong_from5"`
IPLongFrom6 int `json:"iplong_from6"`
IPLongFrom7 int `json:"iplong_from7"`
IPLongTo0 int `json:"iplong_to0"`
IPLongTo1 int `json:"iplong_to1"`
IPLongTo2 int `json:"iplong_to2"`
IPLongTo3 int `json:"iplong_to3"`
IPLongTo4 int `json:"iplong_to4"`
IPLongTo5 int `json:"iplong_to5"`
IPLongTo6 int `json:"iplong_to6"`
IPLongTo7 int `json:"iplong_to7"`
}