Name
geoip - add geographical location data
Description
The geoip handler adds geographical location data associated with the client IP. You can install a database
on Debian systems with apt-get install geoip-database, or see https://mailfud.org/geoip-legacy/.
There is no automatic reloading of the databases under the assumption they will not change that often.
If an IP address does not have associated geographical location data, nothing is added to the context.
Syntax
geoip [subnet] {
city DBFILE4 [DBFILE6]
asn DBFILE4 [DBFILE6]
}
subnet signals if given to use EDNS0 subnet (if present)
for the lookup instead of the source IP address. NOTE: due to security reasons, recursive DNS resolvers
may mask a few bits off of the clients' IP address, which can cause inaccuracies in resolution.
city and asn define the database files that should be used for country, city or AS number
lookups. If the path is relative the path from root will be prepended. At least one database must be
loaded.
Context Keys
The following values will be stored in the context of a request and can be used by other handlers.
The continent codes are: AF: Africa, AN: Antarctica, AS: Asia, EU: Europe, NA: North America,
OC: Oceania, SA: South America.
| Key |
Type |
Example |
Description |
geoip/city |
string |
Cambridge |
The city name in English language. |
geoip/country |
string |
GB |
Country ISO 3166-1 code. |
geoip/country/eu |
bool |
false |
Country is EU member. |
geoip/continent |
string |
EU |
Continent code. |
geoip/latitude |
float64 |
52.2242 |
Base 10, max available precision. |
geoip/longitude |
float64 |
0.1315 |
Base 10, max available precision. |
geoip/timezone |
string |
Europe/London |
The time zone. |
geoip/asn |
int |
37 |
The AS number. |
geoip/asn/organization |
string |
Example Org |
The AS organization. |
Example
Here we add location data to the request's context, so that template can use it in the template creation.
example.org. {
geoip {
city testdata/GeoIPCity.dat
}
template .* {
mytemplate.go.tmpl
}
}