ipdb

package
v0.2.9 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FieldCountryName    = "country_name"
	FieldRegionName     = "region_name"
	FieldCityName       = "city_name"
	FieldISPDomain      = "isp_domain"
	FieldContinentCode  = "continent_code"
	FieldUTCOffset      = "utc_offset"
	FieldLatitude       = "latitude"
	FieldLongitude      = "longitude"
	FieldChinaAdminCode = "china_admin_code"
	FieldOwnerDomain    = "owner_domain"
	FieldTimezone       = "timezone"
	FieldIddCode        = "idd_code"
	FieldCountryCode    = "country_code"
	FieldIDC            = "idc"
	FieldBaseStation    = "base_station"
	FieldCountryCode3   = "country_code3"
	FieldEuropeanUnion  = "european_union"
	FieldCurrencyCode   = "currency_code"
	FieldCurrencyName   = "currency_name"
	FieldAnycast        = "anycast"
)
View Source
const (
	DBFormat = "ipdb"
	DBExt    = ".ipdb"
)
View Source
const (
	FieldsSep = "\t"
)

Variables

CommonFieldsAlias 公共字段到数据库字段映射

FullFields 全字段列表

Functions

func IntToBinaryBE

func IntToBinaryBE(num, length int) []byte

IntToBinaryBE 将int转换为 binary big endian

Types

type Meta

type Meta struct {

	// Build 构建时间 10位时间戳
	Build int `json:"build"`

	// IPVersion IP库版本
	IPVersion int `json:"ip_version"`

	// Languages 支持语言
	// value为语言对应的fields偏移量
	Languages map[string]int `json:"languages"`

	// NodeCount 节点数量
	NodeCount int `json:"node_count"`

	// TotalSize 节点区域和数据区域大小统计
	TotalSize int `json:"total_size"`

	// Fields 数据字段列表
	// 城市级别数据库包含13个字段
	// "country_name": "国家名称"
	// "region_name": "省份名称"
	// "city_name": "城市名称"
	// "owner_domain": "所有者"
	// "isp_domain": "运营商"
	// "latitude": "纬度"
	// "longitude": "经度"
	// "timezone": "时区"
	// "utc_offset": "UTC偏移量"
	// "china_admin_code": "中国邮编"
	// "idd_code": "电话区号"
	// "country_code": "国家代码"
	// "continent_code": "大陆代码"
	Fields []string `json:"fields"`
}

Meta ipdb 元数据

type Reader

type Reader struct {
	// contains filtered or unexported fields
}

Reader is a structure that provides functionalities to read from IPDB IP database.

func NewReader

func NewReader(file string) (*Reader, error)

NewReader initializes a new instance of Reader.

func (*Reader) Close

func (r *Reader) Close() error

Close closes the IP database.

func (*Reader) Find

func (r *Reader) Find(ip net.IP) (*model.IPInfo, error)

Find retrieves IP information based on the given IP address.

func (*Reader) Meta

func (r *Reader) Meta() *model.Meta

Meta returns the meta-information of the IP database.

func (*Reader) SetOption

func (r *Reader) SetOption(option interface{}) error

SetOption configures the Reader with the provided option.

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer provides functionalities to write IP data into IPDB format.

func NewWriter

func NewWriter(meta *model.Meta) (*Writer, error)

NewWriter initializes a new Writer instance for writing IP data in IPDB format.

func (*Writer) Fields

func (w *Writer) Fields(fields []string) int

Fields 保存数据并返回数据的偏移量 相同的数据仅保存一份 数据格式 2 byte length + n byte data

func (*Writer) Insert

func (w *Writer) Insert(info *model.IPInfo) error

Insert adds the given IP information into the writer.

func (*Writer) Nodes

func (w *Writer) Nodes(ip net.IP, mask int) (node, index int, ok bool)

Nodes 获取CIDR地址所在节点和index 将补全Node中间链路,如果中间链路已经有数据,将无法写入新数据

func (*Writer) Resolve

func (w *Writer) Resolve(offset int) string

Resolve 解析数据

func (*Writer) SetOption

func (w *Writer) SetOption(option interface{}) error

SetOption sets the provided options to the Writer.

func (*Writer) WriteTo

func (w *Writer) WriteTo(iw io.Writer) (int64, error)

WriteTo writes the IP data into the provided writer in IPDB format.

type WriterOption

type WriterOption struct {
	// Languages specifies multiple languages for the IPDB format.
	Languages map[string]int
}

WriterOption provides options for the Writer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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