Documentation
¶
Index ¶
Constants ¶
const ( TeredoBit ExtFlags = 0 Charset_ISO_8859_1 Charset = 0 Charset_UTF_8 Charset = 1 CountryBegin = 16776960 LargeCountryBegin = 16515072 StateBeginRev0 = 16700000 StateBeginRev1 = 16000000 StructureInfoMaxSize = 20 DBInfoMaxSize = 100 MaxOrgRecordLength = 300 USOffset = 1 CanadaOffset = 677 WorldOffset = 1353 FIPSRange = 360 SegmentRecordLength = 3 LargeSegmentRecordLength = 4 StandardRecordLength = 3 OrgRecordLength = 4 MaxRecordLength = 4 )
Variables ¶
var ( ErrEmptyIPv4Path = errors.New("empty IPv4 DB path not allowed in CombinedDB initialization") ErrEmptyIPv6Path = errors.New("empty IPv6 DB path not allowed in CombinedDB initialization") )
var ( ErrNoSegments = errors.New("database has no segments, file may be corrupt") ErrInvalidCountryID = errors.New("invalid country id") ErrInvalidIP = errors.New("invalid IP address") ErrNotIPv6 = errors.New("expected IPv6, got IPv4") ErrNegativeIndex = errors.New("index size is negative, database may be corrupt") ErrSegmentNotRead = errors.New("didn't read full segment") )
Functions ¶
This section is empty.
Types ¶
type CombinedDB ¶
type CombinedDB struct {
// contains filtered or unexported fields
}
CombinedDB is a wrapper around the DB struct, allowing automatic IPv4 and IPv6 GeoIP usage
func OpenCombinedDB ¶
func OpenCombinedDB(path4, path6 string) (*CombinedDB, error)
OpenCombinedDB opens the given IPv4 and IPv6 databases and returns a combined database for automatically determining which database file to use when looking up an address. It will return an error if either path is an empty string, and any errors that occured when opening the databases
func (*CombinedDB) Close ¶
func (db *CombinedDB) Close() error
Close closes the databases and returns any errors that occured
func (*CombinedDB) DBv4Path ¶
func (db *CombinedDB) DBv4Path() string
DBv4Path returns the path to the IPv4 database file
func (*CombinedDB) DBv6Path ¶
func (db *CombinedDB) DBv6Path() string
DBv4Path returns the path to the IPv6 database file
func (*CombinedDB) GetCountryByAddr ¶
func (db *CombinedDB) GetCountryByAddr(addr string) (*CountryResult, error)
GetCountryByAddr looks up the country of the given domain or IP address string and returns the result, as well as any errors
func (*CombinedDB) GetCountryByIP ¶
func (db *CombinedDB) GetCountryByIP(ip net.IP) (*CountryResult, error)
GetCountryByIP looks up the country of the given IP address and returns the result, as well as any errors
type CountryResult ¶
type CountryResult struct { Code string Code3 string NameASCII string NameUTF8 string Continent string }
CountryResult is the result of scanning the database for the location of a network address
type DB ¶
type DB struct { Type DBType ModTime time.Time Options *GeoIPOptions Size int64 RecordLength uint8 Charset Charset // contains filtered or unexported fields }
DB represents a legacy GeoIP database, usually having a .dat extension
func OpenDB ¶
func OpenDB(dbPath string, options *GeoIPOptions) (*DB, error)
OpenDB opens and returns the MaxMind GeoIP v1 database, returning the database and any errors
func (*DB) GetCountryByAddr ¶
func (db *DB) GetCountryByAddr(addr string) (*CountryResult, error)
GetCountryByAddr scans the database for the given IP address or domain, returning the result. If a domain is passed to it, it tries to resolve it to an IP, then looks that up.
func (*DB) GetCountryByIP ¶
func (db *DB) GetCountryByIP(ip net.IP) (*CountryResult, error)
GetCountryByIP scans the database for the given IP address, returning the result
func (*DB) GetIndexSize ¶
GetIndexSize returns the size of the database index. If it is negative, something has gone wrong during a read
type DBType ¶
type DBType int
const ( NumDBTypes = (AccuracyRadiusEditionV6 + 1) // GeoIPDBTypes enum InvalidVersion DBType = iota - 1 CountryEdition CityEditionRev1 RegionEditionRev1 ISPEdition OrgEdition CityEditionRev0 RegionEditionRev0 ProxyEdition ASNEdition NetSpeedEdition DomainEdition CountryEditionV6 LocationAEdition AccuracyRadiusEdition CityConfidenceEdition // unsupported CityConfidenceDistEdition // unsupported LargeCountryEdition LargeCountryEditionV6 CityConfidenceDistISPOrgEdition // unused but gaps are not allowed CCMCountryEdition // unused but gaps are not allowed ASNEditionV6 ISPEditionV6 OrgEditionV6 DomainEditionV6 LocationAEditionV6 RegistrarEdition RegistrarEditionV6 UserTypeEdition UserTypeEditionV6 CityEditionRev1V6 CityEditionRev0V6 NetSpeedEditionRev1 NetSpeedEditionRev1V6 CountryConfEdition CityConfEdition RegionConfEdition PostalConfEdition AccuracyRadiusEditionV6 )
type GeoIPDB ¶
type GeoIPDB interface { GetCountryByIP(ip net.IP) (*CountryResult, error) GetCountryByAddr(addr string) (*CountryResult, error) Close() error }
GeoIPDB can be used by functions for geoip-legacy DB and CombinedDB
type GeoIPOptions ¶
GeoIPOptions are used when reading the database file
type NetSpeedValue ¶
type NetSpeedValue int
const ( // GeoIPNetspeedValues enum UnknownSpeed NetSpeedValue = iota DialupSpeed CableDSLSpeed CorporateSpeed )