Documentation
¶
Overview ¶
Package lib package contains traefikgeoip implementations.
Index ¶
- Constants
- func EncodeGeoHash(lat, lng float64) string
- func StringIso88591ToUtf8(value string) string
- func StringUtf8ToIso88591(value string) string
- func StripHeaders(req *http.Request)
- type Classifier
- type Config
- type GeoIPAsnResult
- type GeoIPCityResult
- type GeoIPCountryResult
- type LookupGeoIPAsn
- type LookupGeoIPCity
- type LookupGeoIPCountry
- type Options
- type TraefikGeoIP
- type TraefikGeoIPAsn
- type TraefikGeoIPCity
- type TraefikGeoIPCityAsn
- type TraefikGeoIPCityAsnLightMode
- type TraefikGeoIPCityLightMode
- type TraefikGeoIPCountry
- type TraefikGeoIPCountryAsn
- type TraefikGeoIPNotFound
Constants ¶
const ( // Unknown constant for undefined data. Unknown = "XX" // ContinentHeader continent header name. ContinentHeader = "X-GeoIP-Continent" // ContinentCodeHeader continent code header name. ContinentCodeHeader = "X-GeoIP-Continent-Code" // CountryHeader country header name. CountryHeader = "X-GeoIP-Country" // CountryCodeHeader country code header name. CountryCodeHeader = "X-GeoIP-Country-Code" // RegionHeader region header name. RegionHeader = "X-GeoIP-Region" // RegionCodeHeader region code header name. RegionCodeHeader = "X-GeoIP-Region-Code" // CityHeader city header name. CityHeader = "X-GeoIP-City" // PostalCodeHeader postal code header name. PostalCodeHeader = "X-GeoIP-Postal-Code" // LatitudeHeader latitude header name. LatitudeHeader = "X-GeoIP-Latitude" // LongitudeHeader longitude header name. LongitudeHeader = "X-GeoIP-Longitude" // AccuracyRadiusHeader coord accuracy radius header name. AccuracyRadiusHeader = "X-GeoIP-Accuracy-Radius" // GeohashHeader geohash header name. GeohashHeader = "X-GeoIP-Geohash" // ASNSystemNumberHeader asn system number header name. ASNSystemNumberHeader = "X-GeoIP-ASN-System-Number" // ASNOrganizationHeader asn system organization header name. ASNOrganizationHeader = "X-GeoIP-ASN-Organization" // IPAddressHeader client IP header name. IPAddressHeader = "X-GeoIP-IPAddress" // TrafficTypeHeader traffic classification header. TrafficTypeHeader = "X-Traffic-Type" // TrafficDatacenterHeader datacenter detection header. TrafficDatacenterHeader = "X-Traffic-Datacenter" // TrafficVPNHeader VPN detection header. TrafficVPNHeader = "X-Traffic-VPN" // TrafficTorHeader Tor detection header. TrafficTorHeader = "X-Traffic-Tor" // TrafficAIBotHeader AI bot detection header. TrafficAIBotHeader = "X-Traffic-AI-Bot" )
const DefaultDBPath = "GeoLite2-City.mmdb"
DefaultDBPath default GeoIP2 database path.
Variables ¶
This section is empty.
Functions ¶
func EncodeGeoHash ¶
EncodeGeoHash the point (lat, lng) as a string geohash with the standard 12 characters of precision.
func StringIso88591ToUtf8 ¶
StringIso88591ToUtf8 convert a ISO-8859-1 string in a UTF-8 string.
func StringUtf8ToIso88591 ¶
StringUtf8ToIso88591 convert a UTF-8 string in a ISO-8859-1 string.
func StripHeaders ¶
StripHeaders removes all X-GeoIP-* and X-Traffic-* headers from an inbound request to prevent clients from spoofing middleware-owned headers.
Types ¶
type Classifier ¶
type Classifier struct {
// contains filtered or unexported fields
}
Classifier holds traffic classification data loaded from external lists.
func NewClassifier ¶
func NewClassifier(config *Config) *Classifier
NewClassifier creates a new Classifier and performs the initial data load.
type Config ¶
type Config struct {
CityDBPath string `json:"cityDbPath,omitempty"`
AsnDBPath string `json:"asnDbPath,omitempty"`
CountryDBPath string `json:"countryDbPath,omitempty"`
PreferXForwardedForHeader bool
IPHeader string `json:"ipHeader,omitempty"`
FailInError bool `json:"failInError,omitempty"`
Debug bool `json:"debug,omitempty"`
LightMode bool `json:"lightMode,omitempty"`
Iso88591 bool `json:"iso88591,omitempty"`
DatacenterFile string `json:"datacenterFile,omitempty"`
VPNFile string `json:"vpnFile,omitempty"`
TorFile string `json:"torFile,omitempty"`
AIBotFile string `json:"aiBotFile,omitempty"`
RefreshSeconds int `json:"refreshSeconds,omitempty"`
}
Config the plugin configuration.
type GeoIPAsnResult ¶
type GeoIPAsnResult struct {
// contains filtered or unexported fields
}
GeoIPAsnResult in memory, this should have between 126 and 180 bytes. On average, consider 150 bytes.
type GeoIPCityResult ¶
type GeoIPCityResult struct {
// contains filtered or unexported fields
}
GeoIPCityResult in memory, this should have between 126 and 180 bytes. On average, consider 150 bytes.
type GeoIPCountryResult ¶
type GeoIPCountryResult struct {
// contains filtered or unexported fields
}
GeoIPCountryResult in memory, this should have between 126 and 180 bytes. On average, consider 150 bytes.
type LookupGeoIPAsn ¶
type LookupGeoIPAsn func(ip net.IP) (*GeoIPAsnResult, error)
LookupGeoIPAsn LookupGeoIP.
func CreateAsnDBLookup ¶
func CreateAsnDBLookup(rdr *geoip2.ASNReader) LookupGeoIPAsn
CreateAsnDBLookup CreateCountryDBLookup.
func CreateAsnDBLookupIso88591 ¶
func CreateAsnDBLookupIso88591(rdr *geoip2_iso88591.ASNReader) LookupGeoIPAsn
CreateAsnDBLookupIso88591 CreateCountryDBLookup.
func NewLookupAsn ¶
func NewLookupAsn(dbPath, name string, iso88591 bool) (LookupGeoIPAsn, error)
NewLookupAsn Create a new Lookup.
type LookupGeoIPCity ¶
type LookupGeoIPCity func(ip net.IP) (*GeoIPCityResult, error)
LookupGeoIPCity LookupGeoIP.
func CreateCityDBLookup ¶
func CreateCityDBLookup(rdr *geoip2.CityReader) LookupGeoIPCity
CreateCityDBLookup CreateCityDBLookup.
func CreateCityDBLookupIso88591 ¶
func CreateCityDBLookupIso88591(rdr *geoip2_iso88591.CityReader) LookupGeoIPCity
CreateCityDBLookupIso88591 CreateCityDBLookup.
func NewLookupCity ¶
func NewLookupCity(dbPath, name string, iso88591 bool) (LookupGeoIPCity, error)
NewLookupCity Create a new Lookup.
type LookupGeoIPCountry ¶
type LookupGeoIPCountry func(ip net.IP) (*GeoIPCountryResult, error)
LookupGeoIPCountry LookupGeoIPCountry.
func CreateCountryDBLookup ¶
func CreateCountryDBLookup(rdr *geoip2.CountryReader) LookupGeoIPCountry
CreateCountryDBLookup CreateCountryDBLookup.
func CreateCountryDBLookupIso88591 ¶
func CreateCountryDBLookupIso88591(rdr *geoip2_iso88591.CountryReader) LookupGeoIPCountry
CreateCountryDBLookupIso88591 CreateCountryDBLookup.
func NewLookupCountry ¶
func NewLookupCountry(dbPath, name string, iso88591 bool) (LookupGeoIPCountry, error)
NewLookupCountry Create a new Lookup.
type Options ¶
type Options struct {
PreferXForwardedForHeader bool
IPHeader string `json:"ipHeader,omitempty"`
FailInError bool `json:"failInError,omitempty"`
Debug bool `json:"debug,omitempty"`
LightMode bool `json:"lightMode,omitempty"`
Iso88591 bool `json:"iso88591,omitempty"`
}
Options the plugin options.
func ConfigToOptions ¶
ConfigToOptions converts the plugin configuration to plugin options.
type TraefikGeoIP ¶
type TraefikGeoIP struct {
Next http.Handler
Name string
Options Options
Classifier *Classifier
}
TraefikGeoIP is a middleware that put ip in header.
func (*TraefikGeoIP) ServeHTTP ¶
func (mw *TraefikGeoIP) ServeHTTP(reqWr http.ResponseWriter, req *http.Request)
type TraefikGeoIPAsn ¶
type TraefikGeoIPAsn struct {
Next http.Handler
Name string
Options Options
Classifier *Classifier
LookupAsn LookupGeoIPAsn
}
TraefikGeoIPAsn is a middleware that looks up the city of the client IP address from the GeoIP2 database.
func (*TraefikGeoIPAsn) ServeHTTP ¶
func (mw *TraefikGeoIPAsn) ServeHTTP(reqWr http.ResponseWriter, req *http.Request)
type TraefikGeoIPCity ¶
type TraefikGeoIPCity struct {
Next http.Handler
Name string
Options Options
Classifier *Classifier
LookupCity LookupGeoIPCity
}
TraefikGeoIPCity is a middleware that looks up the city of the client IP address from the GeoIP2 database.
func (*TraefikGeoIPCity) ServeHTTP ¶
func (mw *TraefikGeoIPCity) ServeHTTP(reqWr http.ResponseWriter, req *http.Request)
type TraefikGeoIPCityAsn ¶
type TraefikGeoIPCityAsn struct {
Next http.Handler
Name string
Options Options
Classifier *Classifier
LookupAsn LookupGeoIPAsn
LookupCity LookupGeoIPCity
}
TraefikGeoIPCityAsn is a middleware that looks up the city of the client IP address from the GeoIP2 database.
func (*TraefikGeoIPCityAsn) ServeHTTP ¶
func (mw *TraefikGeoIPCityAsn) ServeHTTP(reqWr http.ResponseWriter, req *http.Request)
type TraefikGeoIPCityAsnLightMode ¶
type TraefikGeoIPCityAsnLightMode struct {
Next http.Handler
Name string
Options Options
Classifier *Classifier
LookupAsn LookupGeoIPAsn
LookupCity LookupGeoIPCity
}
TraefikGeoIPCityAsnLightMode is a middleware that looks up the city of the client IP address from the GeoIP2 database.
func (*TraefikGeoIPCityAsnLightMode) ServeHTTP ¶
func (mw *TraefikGeoIPCityAsnLightMode) ServeHTTP(reqWr http.ResponseWriter, req *http.Request)
type TraefikGeoIPCityLightMode ¶
type TraefikGeoIPCityLightMode struct {
Next http.Handler
Name string
Options Options
Classifier *Classifier
LookupCity LookupGeoIPCity
}
TraefikGeoIPCityLightMode is a middleware that looks up the city of the client IP address from the GeoIP2 database.
func (*TraefikGeoIPCityLightMode) ServeHTTP ¶
func (mw *TraefikGeoIPCityLightMode) ServeHTTP(reqWr http.ResponseWriter, req *http.Request)
type TraefikGeoIPCountry ¶
type TraefikGeoIPCountry struct {
Next http.Handler
Name string
Options Options
Classifier *Classifier
LookupCountry LookupGeoIPCountry
}
TraefikGeoIPCountry is a middleware that looks up the city of the client IP address from the GeoIP2 database.
func (*TraefikGeoIPCountry) ServeHTTP ¶
func (mw *TraefikGeoIPCountry) ServeHTTP(reqWr http.ResponseWriter, req *http.Request)
type TraefikGeoIPCountryAsn ¶
type TraefikGeoIPCountryAsn struct {
Next http.Handler
Name string
Options Options
Classifier *Classifier
LookupAsn LookupGeoIPAsn
LookupCountry LookupGeoIPCountry
}
TraefikGeoIPCountryAsn is a middleware that looks up the city of the client IP address from the GeoIP2 database.
func (*TraefikGeoIPCountryAsn) ServeHTTP ¶
func (mw *TraefikGeoIPCountryAsn) ServeHTTP(reqWr http.ResponseWriter, req *http.Request)
type TraefikGeoIPNotFound ¶
type TraefikGeoIPNotFound struct {
Next http.Handler
Name string
Options Options
Classifier *Classifier
}
TraefikGeoIPNotFound is a middleware that handles the case when no GeoIP DB is configured.
func (*TraefikGeoIPNotFound) ServeHTTP ¶
func (mw *TraefikGeoIPNotFound) ServeHTTP(reqWr http.ResponseWriter, req *http.Request)