-
Notifications
You must be signed in to change notification settings - Fork 274
/
resolver.go
80 lines (70 loc) · 2.33 KB
/
resolver.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
package geo
import "errors"
const (
MaxmindType = "maxmind"
DummyType = "dummy"
UKCountry = "UK"
)
var (
EmptyIP = errors.New("IP is empty")
EUCountries = map[string]bool{
"BE": true,
"EL": true,
"LT": true,
"PT": true,
"BG": true,
"ES": true,
"LU": true,
"RO": true,
"CZ": true,
"FR": true,
"HU": true,
"SI": true,
"DK": true,
"HR": true,
"MT": true,
"SK": true,
"DE": true,
"IT": true,
"NL": true,
"FI": true,
"EE": true,
"CY": true,
"AT": true,
"SE": true,
"IE": true,
"LV": true,
"PL": true,
}
)
//Resolver is a geo based location data resolver
type Resolver interface {
Resolve(ip string) (*Data, error)
Type() string
Close() error
}
//Data is a geo location data dto
type Data struct {
Continent string `mapstructure:"continent,omitempty" json:"continent,omitempty"`
Country string `mapstructure:"country,omitempty" json:"country,omitempty"`
CountryName string `mapstructure:"country_name,omitempty" json:"country_name,omitempty"`
City string `mapstructure:"city,omitempty" json:"city,omitempty"`
Lat float64 `mapstructure:"latitude,omitempty" json:"latitude,omitempty"`
Lon float64 `mapstructure:"longitude,omitempty" json:"longitude,omitempty"`
Zip string `mapstructure:"zip,omitempty" json:"zip,omitempty"`
Region string `mapstructure:"region,omitempty" json:"region,omitempty"`
ASN uint `mapstructure:"autonomous_system_number,omitempty" json:"autonomous_system_number,omitempty"`
ASO string `mapstructure:"autonomous_system_organization,omitempty" json:"autonomous_system_organization,omitempty"`
ISP string `mapstructure:"isp,omitempty" json:"isp,omitempty"`
Organization string `mapstructure:"organization,omitempty" json:"organization,omitempty"`
Domain string `mapstructure:"domain,omitempty" json:"domain,omitempty"`
}
//ResolverConfig is a dto for geo data resolver config serialization
type ResolverConfig struct {
Type string `mapstructure:"type" json:"type,omitempty" yaml:"type,omitempty"`
Config interface{} `mapstructure:"config" json:"config,omitempty" yaml:"config,omitempty"`
}
//MaxMindConfig is a dto for MaxMind configuration serialization
type MaxMindConfig struct {
MaxMindURL string `mapstructure:"maxmind_url" json:"maxmind_url,omitempty" yaml:"maxmind_url,omitempty"`
}