Documentation ¶
Overview ¶
Package mmdatformat implements the version 1 MaxMind database (dat) format
Index ¶
- Constants
- Variables
- func ContainsOnlyNumericCharacters(s string) bool
- func DecodeRecordUint32(b []byte, length int) (record uint32, err error)
- func EncodeRecord(v interface{}, length int) (record []byte, err error)
- func GetISO2CountryCodeIndex(countryCode string) (idx int, err error)
- func GetISO2CountryCodeString(idx int) (countryCode string, err error)
- func GetISO3CountryCodeIndex(countryCode string) (idx int, err error)
- func GetISO3CountryCodeString(idx int) (countryCode string, err error)
- func LookupType(dbType geodbtools.DatabaseType) (t Type, typeID DatabaseTypeID, err error)
- func MustRegisterType(typeID DatabaseTypeID, t Type)
- func NewReader(r geodbtools.ReaderSource) (reader geodbtools.Reader, meta geodbtools.Metadata, err error)
- func NewWriter(w io.Writer, t Type, typeID DatabaseTypeID) geodbtools.Writer
- func RegisterType(typeID DatabaseTypeID, t Type) (err error)
- type DatabaseTypeID
- type Type
Constants ¶
const ( // DatabaseTypeIDBase defines the base value for database types // Newer databases have this offset added to their actual type value, older not. DatabaseTypeIDBase DatabaseTypeID = 105 // DatabaseTypeIDCountryEdition is an IPv4 country database DatabaseTypeIDCountryEdition = DatabaseTypeIDBase + 1 // DatabaseTypeIDCountryEditionV6 is an IPv6 country database DatabaseTypeIDCountryEditionV6 = DatabaseTypeIDBase + 12 )
Variables ¶
var ( // ErrUnsupportedRecordType indicates that a record type is unsupported ErrUnsupportedRecordType = errors.New("unsupported record type") // ErrDatabaseInfoNotFound indicates that the database information could not be found ErrDatabaseInfoNotFound = errors.New("database information not found") )
var ( // ErrTypeRegistered indicates that the database type has already been registered ErrTypeRegistered = errors.New("database type is registered") // ErrTypeNotFound indicates that the database type has not been found ErrTypeNotFound = errors.New("database type not found") )
var ( // ErrCountryNotFound indicates that a country was not found ErrCountryNotFound = errors.New("country not found") )
Functions ¶
func ContainsOnlyNumericCharacters ¶
ContainsOnlyNumericCharacters checks if a given string contains only numeric characters (0-9)
func DecodeRecordUint32 ¶
DecodeRecordUint32 decodes a record to an uint32 value
func EncodeRecord ¶
EncodeRecord encodes the given value as a record of the given length
func GetISO2CountryCodeIndex ¶
GetISO2CountryCodeIndex retrieves the index of a given GeoIP country code in 2 char format
func GetISO2CountryCodeString ¶
GetISO2CountryCodeString retrieves the 2-char country code for a given index
func GetISO3CountryCodeIndex ¶
GetISO3CountryCodeIndex retrieves the index of a given GeoIP country code in 3 char format
func GetISO3CountryCodeString ¶
GetISO3CountryCodeString retrieves the 3-char country code for a given index
func LookupType ¶
func LookupType(dbType geodbtools.DatabaseType) (t Type, typeID DatabaseTypeID, err error)
LookupType retrieves the type for a given geodbtools.DatabaseType string
func MustRegisterType ¶
func MustRegisterType(typeID DatabaseTypeID, t Type)
MustRegisterType registers a database type and panics on error
func NewReader ¶
func NewReader(r geodbtools.ReaderSource) (reader geodbtools.Reader, meta geodbtools.Metadata, err error)
NewReader initializes a new reader
func NewWriter ¶
func NewWriter(w io.Writer, t Type, typeID DatabaseTypeID) geodbtools.Writer
NewWriter returns a new writer instance
func RegisterType ¶
func RegisterType(typeID DatabaseTypeID, t Type) (err error)
RegisterType registers a database type
Types ¶
type Type ¶
type Type interface { // DatabaseType returns the database type DatabaseType() geodbtools.DatabaseType // EncodeTreeNode encodes a given tree node and returns its representation as a byte-slice, along with additional // nodes that need processing EncodeTreeNode(position *uint32, node *geodbtools.RecordTree) (b []byte, additionalNodes []*geodbtools.RecordTree, err error) // NewReader returns a new database reader, given generic information obtained from the source NewReader(source geodbtools.ReaderSource, dbType DatabaseTypeID, dbInfo string, buildTime *time.Time) (reader geodbtools.Reader, meta geodbtools.Metadata, err error) // NewWriter returns a new database writer NewWriter(w io.Writer, ipVersion geodbtools.IPVersion) (writer geodbtools.Writer, err error) }
Type describes a database type
func LookupTypeByDatabaseType ¶
func LookupTypeByDatabaseType(typeID DatabaseTypeID) (t Type, err error)
LookupTypeByDatabaseType retrieves the type for a given DatabaseTypeID constant