Documentation
¶
Index ¶
- Constants
- func CountryCodeToName(code string) (string, error)
- func CountryCodeToRegion(code string) string
- func CountryNameToCode(name string) (string, error)
- type Client
- func (client *Client) ClearCache()
- func (client *Client) CountryCode(ipaddress string) (string, error)
- func (client *Client) CountryName(ipaddress string) (string, error)
- func (client *Client) Lookup(ipaddress string) (*IPLocation, error)
- func (client *Client) RegionName(ipaddress string) (string, error)
- func (client *Client) TimeZone(ipaddress string) (string, error)
- type Continent
- type Country
- type Database
- func (database *Database) ClearCache()
- func (database *Database) CountryCode(ipaddress string) (string, error)
- func (database *Database) CountryName(ipaddress string) (string, error)
- func (database *Database) Lookup(ipaddress string) (*IPLocation, error)
- func (database *Database) RegionName(ipaddress string) (string, error)
- func (database *Database) TimeZone(ipaddress string) (string, error)
- type DatabaseDownloader
- type GPSCoordinate
- type IPLocation
- func (ipLocation *IPLocation) ApproximateGPSCoordinate() *GPSCoordinate
- func (ipLocation *IPLocation) ContinentCode() string
- func (ipLocation *IPLocation) ContinentName() string
- func (ipLocation *IPLocation) CountryCode() string
- func (ipLocation *IPLocation) CountryName() string
- func (ipLocation *IPLocation) RegionName() string
- func (ipLocation *IPLocation) SubdivisionCodes() []string
- func (ipLocation *IPLocation) SubdivisionNames() []string
- func (ipLocation *IPLocation) TimeZone() string
- type Location
- type Subdivision
Constants ¶
const DefaultChecksumExt = ".sha256"
DefaultChecksumExt is the default extension for the local checksum
const DefaultChecksumURL = "https://download.maxmind.com/app/geoip_download?suffix=tar.gz.sha256"
DefaultChecksumURL is the URL where to download the checksum file
const DefaultDownloadURL = "https://download.maxmind.com/app/geoip_download?suffix=tar.gz"
DefaultDownloadURL is the URL where to download the tgz file
Variables ¶
This section is empty.
Functions ¶
func CountryCodeToName ¶
CountryCodeToName translates an ISO country to the English name
func CountryCodeToRegion ¶
CountryCodeToRegion translates an ISO country code to a region Defaults to "west-europe"
func CountryNameToCode ¶
CountryNameToCode translates the country name to it's ISO country code
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is used to get the results from the server API
func (*Client) ClearCache ¶
func (client *Client) ClearCache()
ClearCache clears the cache for the lookups
func (*Client) CountryCode ¶
CountryCode returns the country code for a specific IP address
func (*Client) CountryName ¶
CountryName returns the country name for a specific IP address
func (*Client) Lookup ¶
func (client *Client) Lookup(ipaddress string) (*IPLocation, error)
Lookup returns the full country information for a specific IP address
func (*Client) RegionName ¶
RegionName returns the region name for a specific IP address
Region can be: - west-us - south-brazil - japan-east - southeast-asia - west-europe (the default)
type Continent ¶
type Continent struct { ISOCode string `maxminddb:"code"` // The continent code Names map[string]string `maxminddb:"names"` // The names for this continent }
Continent defines the continent information for an IP location
type Country ¶
type Country struct { ISOCode string `maxminddb:"iso_code"` // The ISO country code Names map[string]string `maxminddb:"names"` // The names for this country }
Country defines the country information for an IP location
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
Database is the main wrapper around the MaxMind GeoIP database
func NewDatabase ¶
NewDatabase returns a new Database instance with the given database path
func (*Database) ClearCache ¶
func (database *Database) ClearCache()
ClearCache clears the cache for the lookups
func (*Database) CountryCode ¶
CountryCode returns the country code for a specific IP address
func (*Database) CountryName ¶
CountryName returns the country name for a specific IP address
func (*Database) Lookup ¶
func (database *Database) Lookup(ipaddress string) (*IPLocation, error)
Lookup returns the full country information for a specific IP address
func (*Database) RegionName ¶
RegionName returns the region name for a specific IP address
Region can be: - west-us - south-brazil - japan-east - southeast-asia - west-europe (the default)
type DatabaseDownloader ¶
type DatabaseDownloader struct { LicenseKey string // The license key to use for the downloads TargetFilePath string // The path where to store the database DownloadURL string // The URL where to download the tgz file ChecksumURL string // The URL where to download the remote checksum // contains filtered or unexported fields }
DatabaseDownloader is a struct used to download the GeoLite database from maxmind
func NewDatabaseDownloader ¶
func NewDatabaseDownloader(licenseKey string, targetFilePath string, timeout time.Duration) *DatabaseDownloader
NewDatabaseDownloader returns a new DatabaseDownloader instance configured with the default URLs
func (*DatabaseDownloader) Download ¶
func (downloader *DatabaseDownloader) Download() error
Download performs the actual download of the database
func (*DatabaseDownloader) LocalChecksum ¶
func (downloader *DatabaseDownloader) LocalChecksum() (string, error)
LocalChecksum returns the local checksum if any
func (*DatabaseDownloader) RemoteChecksum ¶
func (downloader *DatabaseDownloader) RemoteChecksum() (string, error)
RemoteChecksum returns the remote checksum
func (*DatabaseDownloader) ShouldDownload ¶
func (downloader *DatabaseDownloader) ShouldDownload() (bool, error)
ShouldDownload checks if a download is needed or not
It does this by comparing the local and remote checksum. If they are different, a download is needed
type GPSCoordinate ¶
type GPSCoordinate struct { Latitude float64 `maxminddb:"latitude"` // The latitude for this location Longitude float64 `maxminddb:"longitude"` // The longitude for this location }
GPSCoordinate defines a GPS coordinate
type IPLocation ¶
type IPLocation struct { IPAddress string Continent *Continent `maxminddb:"continent"` Country *Country `maxminddb:"country"` Location *Location `maxminddb:"location"` Subdivisions []*Subdivision `maxminddb:"subdivisions"` IsCached bool }
IPLocation defines all info we know about a location based on it's IP address
func (*IPLocation) ApproximateGPSCoordinate ¶
func (ipLocation *IPLocation) ApproximateGPSCoordinate() *GPSCoordinate
ApproximateGPSCoordinate returns the GPS coordinates for the location
func (*IPLocation) ContinentCode ¶
func (ipLocation *IPLocation) ContinentCode() string
ContinentCode returns the ISO country code for the location
func (*IPLocation) ContinentName ¶
func (ipLocation *IPLocation) ContinentName() string
ContinentName returns the country name for the location in English
func (*IPLocation) CountryCode ¶
func (ipLocation *IPLocation) CountryCode() string
CountryCode returns the ISO country code for the location
func (*IPLocation) CountryName ¶
func (ipLocation *IPLocation) CountryName() string
CountryName returns the country name for the location in English
func (*IPLocation) RegionName ¶
func (ipLocation *IPLocation) RegionName() string
RegionName returns the region name for the location in English
func (*IPLocation) SubdivisionCodes ¶
func (ipLocation *IPLocation) SubdivisionCodes() []string
SubdivisionCodes returns the codes for the subdivisions
func (*IPLocation) SubdivisionNames ¶
func (ipLocation *IPLocation) SubdivisionNames() []string
SubdivisionNames returns the names for the subdivisions
func (*IPLocation) TimeZone ¶
func (ipLocation *IPLocation) TimeZone() string
TimeZone returns the timezone for the location
type Location ¶
type Location struct { GPSCoordinate TimeZone string `maxminddb:"time_zone"` // The timezone for this location }
Location defines all the location information we know such as timezone, lat and lon
type Subdivision ¶
type Subdivision struct { ISOCode string `maxminddb:"iso_code"` // The ISO subdivision code Names map[string]string `maxminddb:"names"` // The names for this subdivision }
Subdivision defines a subdivision of the country (state, province)