forked from NiceLabs/geoip-seeker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrecord.go
41 lines (38 loc) · 1.31 KB
/
record.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
package ipdb
import (
"strings"
. "github.com/OpenIPDB/geoip-seeker/shared"
)
func makeRecord(data string, language uint8, fields []string) (record *Record) {
record = new(Record)
values := strings.Split(data, "\t")
values = values[language : language+uint8(len(fields))]
mapping := map[string]*string{
"country_name": &record.CountryName,
"region_name": &record.RegionName,
"city_name": &record.CityName,
"owner_domain": &record.OwnerDomain,
"isp_domain": &record.ISPDomain,
"latitude": &record.Latitude,
"longitude": &record.Longitude,
"timezone": &record.TimeZone,
"utc_offset": &record.UTCOffset,
"idd_code": &record.IDDCode,
"china_admin_code": &record.GB2260Code,
"country_code": &record.ISO3166Alpha2Code,
"country_code3": &record.ISO3166Alpha3Code,
"continent_code": &record.ContinentCode,
"idc": &record.IDC,
"base_station": &record.BaseStation,
"currency_code": &record.CurrencyCode,
"currency_name": &record.CurrencyName,
"european_union": &record.EuropeanUnion,
"anycast": &record.AnyCast,
}
for index, end := language, language+uint8(len(fields)); index < end; index++ {
if input, ok := mapping[fields[index]]; ok {
*input = values[index]
}
}
return record
}