Documentation
¶
Overview ¶
Package ipdb provides facilities for parsing IPDB files served by ipip.net, (maybe) works better than the official package. Compared to the official implementation, it provides some easier ways to look into the database, and allows you to focus more on your project without hesitation.
A simple way to make queries to the database is, of course the database must be loaded in “IPDb”, Search the IP, then pass the return value as offset and Get what you want.
Besides, the implementation of iptree (type Node and Leaf) is to help buiding the full database in to an binary tree, maybe useful in some particular situations.
Index ¶
- type IPDb
- func (d *IPDb) GetAllFields(offset uint32) (map[string]map[string]string, error)
- func (d *IPDb) GetAllFieldsLocale(offset uint32, lang string) (map[string]string, error)
- func (d *IPDb) GetBuildTime() time.Time
- func (d *IPDb) GetLanguages() []string
- func (d *IPDb) GetRaw(offset uint32) ([]byte, error)
- func (d *IPDb) GetValue(offset uint32, field string) (map[string]string, error)
- func (d *IPDb) GetValueLocale(offset uint32, field, lang string) (string, error)
- func (d *IPDb) GrowTree() (*iptree.Node, error)
- func (d *IPDb) IsIPv4Db() bool
- func (d *IPDb) IsIPv6Db() bool
- func (d *IPDb) Search(ip net.IP) (uint32, error)
- type Metadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IPDb ¶
type IPDb struct { FileSize uint64 Metadata Metadata Data []byte // contains filtered or unexported fields }
IPDb stores the whole IPDB file
func NewIPDb ¶
NewIPDb reads the IPDB file by providing filepath, returning an IPDb instance or error.
func (*IPDb) GetAllFields ¶
GetAllFields returns the data mapping by giving the offset, or error. BE AWARE: The return value stores the data in the form “map[field]map[lang]data”.
func (*IPDb) GetAllFieldsLocale ¶
GetAllFieldsLocale returns the data mapping by giving the offset, in the providing locale “lang”, or error.
func (*IPDb) GetBuildTime ¶
GetBuildTime converts build number in metadata into time.Time.
func (*IPDb) GetLanguages ¶
GetLanguages returns the languages supported by the database.
func (*IPDb) GetValue ¶
GetValue returns the values in all locale, by giving offset and field, or error.
func (*IPDb) GetValueLocale ¶
GetValueLocale returns the values in the providing locale “lang”, by giving offset and field, or error.
type Metadata ¶
type Metadata struct { Build int64 `json:"build"` IPVersion uint16 `json:"ip_version"` Languages map[string]int `json:"languages"` NodeCount uint32 `json:"node_count"` TotalSize uint64 `json:"total_size"` Fields []string `json:"fields"` }
Metadata stores the metadata of the IPDB file