Documentation
¶
Overview ¶
Package geo provides functionality for looking up country code and ISP name of the given IP address.
Index ¶
- func ASN(db *geoip2.Reader, ip net.IP) (string, error)
- func City(db *geoip2.Reader, ip net.IP) (string, string, error)
- func CountryCode(db *geoip2.Reader, ip net.IP) (string, error)
- func FromFile(filePath string) (*lookup, error)
- func FromWeb(dbURL string, nameInTarball string, syncInterval time.Duration, ...) *lookup
- func ISP(db *geoip2.Reader, ip net.IP) (string, error)
- func LatLong(db *geoip2.Reader, ip net.IP) (float64, float64, error)
- func LatLongFromWeb(dbURL string, nameInTarball string, syncInterval time.Duration, ...) *lookup
- func New(dbURL string, syncInterval time.Duration, filePath string, ...) *lookup
- type CityLookup
- type CountryLookup
- type ISPLookup
- type LatLongLookup
- type Lookup
- type NoLookup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromWeb ¶
func FromWeb(dbURL string, nameInTarball string, syncInterval time.Duration, filePath string, lookupForValidation func(*geoip2.Reader, net.IP) (string, error)) *lookup
FromWeb is same as New but allows downloading a different MaxMind database lookupForValidation is a function that we call to validate new databases as they're loaded.
func LatLongFromWeb ¶
func LatLongFromWeb(dbURL string, nameInTarball string, syncInterval time.Duration, filePath string, lookupForValidation func(*geoip2.Reader, net.IP) (float64, float64, error)) *lookup
LatLongFromWeb is same as New but allows downloading a different MaxMind database for lat/long lookup lookupForValidation is a function that we call to validate new databases as they're loaded.
func New ¶
func New(dbURL string, syncInterval time.Duration, filePath string, lookupForValidation func(*geoip2.Reader, net.IP) (string, error)) *lookup
New constructs a new Lookup from the MaxMind GeoLite2 Country database fetched from the given URL and keeps in sync with it every syncInterval. If filePath is not empty, it saves the database file to filePath and uses the file if available. lookupForValidation is a function that we call to validate new databases as they're loaded.
Types ¶
type CityLookup ¶
type CountryLookup ¶
type CountryLookup interface { // CountryCode looks up the 2 digit ISO 3166 country code in upper case for // the given IP address and returns "" if there was an error. CountryCode(ip net.IP) string }
CountryLookup allows looking up the country for an IP address
type ISPLookup ¶
type ISPLookup interface { // ISP looks up the ISP name for the given IP address and returns "" if there was an error. ISP(ip net.IP) string // ASN looks up the ASN number (e.g. AS62041) for the given IP address and returns "" if there was an error. ASN(ip net.IP) string }
ISPLookup allows looking up ISP information for an IP address
type LatLongLookup ¶
type Lookup ¶
type Lookup interface { CountryLookup ISPLookup CityLookup LatLongLookup // Ready returns a channel which is closed when the lookup is ready to // serve requests. Ready() <-chan struct{} }