Documentation ¶
Overview ¶
Package geoip provides a thin wrapper around libGeoIP for looking up geographical information about IP addresses.
Example ¶
g, err := Open(*dbFile, nil) if err != nil { panic(err) } defer g.Close() fmt.Printf("%#v\n", g.Lookup("24.24.24.24"))
Output: &geoip.Record{CountryCode:"US", CountryCode3:"USA", CountryName:"United States", Region:"NY", City:"Deer Park", PostalCode:"11729", Latitude:40.762699127197266, Longitude:-73.32270050048828, AreaCode:631, ContinentCode:"NA"}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultOptions = &Options{ Caching: CacheDefault, ReloadOnUpdate: true, UseMMap: true, }
DefaultOptions caches no data, reloads on updates, and uses MMAP.
Functions ¶
func GetRegionName ¶
func GetTimeZone ¶
Types ¶
type CachingStrategy ¶
type CachingStrategy int
CachingStrategy determines what data libGeoIP will cache.
const ( // CacheDefault caches no data. CacheDefault CachingStrategy = C.GEOIP_STANDARD // CacheAll caches all data in memory. CacheAll CachingStrategy = C.GEOIP_MEMORY_CACHE // CacheMRU caches the most recently used data in memory. CacheMRU CachingStrategy = C.GEOIP_INDEX_CACHE )
type Database ¶
type Database struct {
// contains filtered or unexported fields
}
A Database is a GeoIP database.
func Open ¶
Open returns an open DB instance of the given .dat file. The result *must* be closed, or memory will leak.
type Options ¶
type Options struct { Caching CachingStrategy // Caching determines what data will be cached. ReloadOnUpdate bool // ReloadOnUpdate will watch the data files for updates. UseMMap bool // UseMMap enables MMAP for the data files. }
Options are the set of options provided by libGeoIP.
type Record ¶
type Record struct { CountryCode string // CountryCode is a two-letter country code. CountryCode3 string // CountryCode3 is a three-letter country code. CountryName string // CountryName is the name of the country. Region string // Region is the geographical region of the location. City string // City is the name of the city. PostalCode string // PostalCode is the location's postal code. Latitude float64 // Latitude is the location's latitude. Longitude float64 // Longitude is the location's longitude. AreaCode int // AreaCode is the location's area code. ContinentCode string // ContinentCode is the location's continent. }
Record is a GeoIP record.
Click to show internal directories.
Click to hide internal directories.