\fIgeoip\fP - Lookup maxmind geoip2 databases using the client IP, then add associated geoip data to the context request.
.SH"DESCRIPTION"
.PP
The \fIgeoip\fP plugin add geo location data associated with the client IP, it allows you to configure a geoIP2 maxmind database
\[la]https://dev.maxmind.com/geoip/docs/databases\[ra] to add the geo location data associated with the IP address.
.PP
The data is added leveraging the \fImetadata\fP plugin, values can then be retrieved using it as well, for example:
.PP
.RS
.nf
import (
"strconv"
"github.com/coredns/coredns/plugin/metadata"
)
// ...
if getLongitude := metadata.ValueFunc(ctx, "geoip/longitude"); getLongitude != nil {
if longitude, err := strconv.ParseFloat(getLongitude(), 64); err == nil {
// Do something useful with longitude.
}
} else {
// The metadata label geoip/longitude for some reason, was not set.
}
// ...
.fi
.RE
.SH"DATABASES"
.PP
The supported databases use city schema such as \fB\fCCity\fR and \fB\fCEnterprise\fR. Other databases types with different schemas are not supported yet.
The following configuration configures the \fB\fCCity\fR database.
.PP
.RS
.nf
\&. {
geoip /opt/geoip2/db/GeoLite2\-City.mmdb
metadata # Note that metadata plugin must be enabled as well.
}
.fi
.RE
.SH"METADATADA LABELS"
.PP
A limited set of fields will be exported as labels, all values are stored using strings \fBregardless of their underlying value type\fP, and therefore you may have to convert it back to its original type, note that numeric values are always represented in base 10.