Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Providers = map[string]*Provider{ "freegeoip.app": { Name: "freegeoip.app", TemplateURL: "https://freegeoip.app/json/%[1]s", Mappings: Location{ CountryCode: "country_code", Country: "country_name", RegionCode: "region_code", Region: "region_name", City: "city", TimeZone: "time_zone", }, }, "db-ip.com": { Name: "db-ip.com", TemplateURL: "http://api.db-ip.com/v2/free/%[1]s", Mappings: Location{ CountryCode: "countryCode", Country: "countryName", RegionCode: "stateProvCode", Region: "stateProv", City: "city", }, }, "keycdn.com": { Name: "keycdn.com", TemplateURL: "https://tools.keycdn.com/geo.json?host=%[1]s", Mappings: Location{ CountryCode: "data.geo.country_code", Country: "data.geo.country_name", RegionCode: "data.geo.region_code", Region: "data.geo.region_name", City: "data.geo.city", TimeZone: "data.geo.time_zone", ISP: "data.geo.isp", }, }, "ip-api.com": { Name: "ip-api.com", TemplateURL: "http://ip-api.com/json/%[1]s", Mappings: Location{ CountryCode: "countryCode", Country: "country", RegionCode: "region", Region: "regionName", City: "city", TimeZone: "timezone", ISP: "isp", }, }, "ipinfo.io": { Name: "ipinfo.io", TemplateURL: "http://ipinfo.io/%[1]s?token=%[2]s", Mappings: Location{ Country: "country", RegionCode: "region", City: "city", TimeZone: "timezone", ISP: "org", }, }, }
Providers is a map of known providers
Functions ¶
func IsPrivateIP ¶
IsPrivateIP returns true if the given IP address belongs to private network space
Types ¶
type Client ¶
type Client interface { Provider() string GetLocation(ctx context.Context, hostname string) (*Location, error) }
Client is used to retrieve location data from a provider
func GetClients ¶
GetClients creates new clients from the comma separated list of provider names Parameters are supported too, eg: "ipinfo.io xxtokenxx, ip-api.com, freegeoip.app"
type Location ¶
type Location struct { IP string `json:"ip"` Hostname string `json:"hostname,omitempty"` CountryCode string `json:"country_code"` Country string `json:"country"` RegionCode string `json:"region_code"` Region string `json:"region"` City string `json:"city"` TimeZone string `json:"timezone"` ISP string `json:"isp,omitempty"` Source string `json:"source,omitempty"` }
Location contains geographical location and other data of an IP address or hostname
Click to show internal directories.
Click to hide internal directories.