This repository has been archived by the owner on Mar 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
geoip.go
102 lines (96 loc) · 6.27 KB
/
geoip.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
package testutil
import (
"encoding/base64"
"github.com/oschwald/geoip2-golang"
)
const (
// GeoIP2IPv4 contains the only IPv4 in the geoip2 test database
// Location: Milton, Washington, US
GeoIP2IPv4 = "216.160.83.56"
// GeoIP2IPv6 contains the only IPv6 in the geoip2 test database
// Finland, EU
GeoIP2IPv6 = "2a02:d200::1"
)
// GeoIP2Reader returns a city database reader with only 1 ipv4 and 1 ipv6
// address
func GeoIP2Reader() (*geoip2.Reader, error) {
b, err := base64.StdEncoding.DecodeString(encodedGeoip)
if err != nil {
return nil, err
}
return geoip2.FromBytes(b)
}
// made via https://github.com/maxmind/MaxMind-DB/ using write-test-data.pl
const encodedGeoip = `
AAABAAABiAAAAgAAAZEAAAMAAAFHAAAEAAABkQAABQAAAZEAAAYAAAGRAAAHAAABkQAACAAAAQ8AAAkA
AAGRAAAKAAABkQAACwAAAZEAAAwAAAGRAAANAAABkQAADgAAAZEAAA8AAAGRAAAQAAABkQAAEQAAAZEA
ABIAAAGRAAATAAABkQAAFAAAAZEAABUAAAGRAAAWAAABkQAAFwAAAZEAABgAAAGRAAAZAAABkQAAGgAA
AZEAABsAAAGRAAAcAAABkQAAHQAAAZEAAB4AAAGRAAAfAAABkQAAIAAAAZEAACEAAAGRAAAiAAABkQAA
IwAAAZEAACQAAAGRAAAlAAABkQAAJgAAAZEAACcAAAGRAAAoAAABkQAAKQAAAZEAACoAAAGRAAArAAAB
kQAALAAAAZ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