mmdatformat

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package mmdatformat implements the version 1 MaxMind database (dat) format

Index

Constants

View Source
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

View Source
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")
)
View Source
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")
)
View Source
var (
	// ErrCountryNotFound indicates that a country was not found
	ErrCountryNotFound = errors.New("country not found")
)

Functions

func ContainsOnlyNumericCharacters

func ContainsOnlyNumericCharacters(s string) bool

ContainsOnlyNumericCharacters checks if a given string contains only numeric characters (0-9)

func DecodeRecordUint32

func DecodeRecordUint32(b []byte, length int) (record uint32, err error)

DecodeRecordUint32 decodes a record to an uint32 value

func EncodeRecord

func EncodeRecord(v interface{}, length int) (record []byte, err error)

EncodeRecord encodes the given value as a record of the given length

func GetISO2CountryCodeIndex

func GetISO2CountryCodeIndex(countryCode string) (idx int, err error)

GetISO2CountryCodeIndex retrieves the index of a given GeoIP country code in 2 char format

func GetISO2CountryCodeString

func GetISO2CountryCodeString(idx int) (countryCode string, err error)

GetISO2CountryCodeString retrieves the 2-char country code for a given index

func GetISO3CountryCodeIndex

func GetISO3CountryCodeIndex(countryCode string) (idx int, err error)

GetISO3CountryCodeIndex retrieves the index of a given GeoIP country code in 3 char format

func GetISO3CountryCodeString

func GetISO3CountryCodeString(idx int) (countryCode string, err error)

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 DatabaseTypeID

type DatabaseTypeID uint8

DatabaseTypeID represents a DAT database type ID

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL