-
Notifications
You must be signed in to change notification settings - Fork 5
/
agency.go
89 lines (75 loc) · 1.75 KB
/
agency.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
package agency
import (
"bytes"
"encoding/csv"
"strconv"
)
// maxRank is the highest rank that can be used by the data files.
const maxRank = 5
type browser struct {
rank int
typ string
name string
token []byte
}
var browsers []*browser
func init() {
data, _ := dataBrowserCsv()
records, err := csv.NewReader(bytes.NewBuffer(data.bytes)).ReadAll()
if err != nil {
panic("parse error (browser.csv): " + err.Error())
}
for _, record := range records {
rank, _ := strconv.Atoi(record[0])
browsers = append(browsers, &browser{rank, record[1], record[2], []byte(record[3])})
}
}
type device struct {
rank int
typ string
token []byte
}
var devices []*device
func init() {
data, _ := dataDeviceCsv()
records, err := csv.NewReader(bytes.NewBuffer(data.bytes)).ReadAll()
if err != nil {
panic("parse error (device.csv): " + err.Error())
}
for _, record := range records {
rank, _ := strconv.Atoi(record[0])
devices = append(devices, &device{rank, record[1], []byte(record[2])})
}
}
type mobile struct {
token []byte
}
var mobiles []*mobile
func init() {
data, _ := dataMobileCsv()
records, err := csv.NewReader(bytes.NewBuffer(data.bytes)).ReadAll()
if err != nil {
panic("parse error (mobile.csv): " + err.Error())
}
for _, record := range records {
mobiles = append(mobiles, &mobile{[]byte(record[0])})
}
}
type aos struct {
rank int
name string
version string
token []byte
}
var oses []*aos
func init() {
data, _ := dataOsCsv()
records, err := csv.NewReader(bytes.NewBuffer(data.bytes)).ReadAll()
if err != nil {
panic("parse error (os.csv): " + err.Error())
}
for _, record := range records {
rank, _ := strconv.Atoi(record[0])
oses = append(oses, &aos{rank, record[1], record[2], []byte(record[3])})
}
}