mmdb

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 (

	// FieldCity 城市
	FieldCity = "city"

	// FieldContinent 大洲
	FieldContinent = "continent"

	// FieldCountry 国家
	FieldCountry = "country"

	// FieldSubdivisions 行政区
	FieldSubdivisions = "subdivisions"

	// FieldAccuracyRadius 定位精度
	FieldAccuracyRadius = "accuracy_radius"

	// FieldLatitude 纬度
	FieldLatitude = "latitude"

	// FieldLongitude 经度
	FieldLongitude = "longitude"

	// FieldMetroCode 城市代码
	FieldMetroCode = "metro_code"

	// FieldTimeZone 时区
	FieldTimeZone = "time_zone"

	// FieldPostalCode 邮政编码
	FieldPostalCode = "postal_code"

	// FieldRegisteredCountry 注册国家
	FieldRegisteredCountry = "registered_country"

	// FieldRepresentedCountry 代表国家
	FieldRepresentedCountry = "represented_country"

	// FieldRepresentedCountryType 代表国家类型
	FieldRepresentedCountryType = "represented_country_type"

	// FieldIsAnonymousProxy 是否匿名代理
	FieldIsAnonymousProxy = "is_anonymous_proxy"

	// FieldIsSatelliteProvider 是否卫星提供商
	FieldIsSatelliteProvider = "is_satellite_provider"

	// FieldAutonomousSystemNumber 自治系统号
	FieldAutonomousSystemNumber = "autonomous_system_number"

	// FieldAutonomousSystemOrganization 自治系统组织
	FieldAutonomousSystemOrganization = "autonomous_system_organization"
)
View Source
const (
	DBFormat = "mmdb"
	DBExt    = ".mmdb"
)

Variables

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

Functions

func ConvertToMMDBType added in v0.2.1

func ConvertToMMDBType(value interface{}) (mmdbtype.DataType, error)

ConvertToMMDBType converts a given value to an appropriate MMDB data type. If the value is a complex type (e.g., struct or map), it uses reflection to handle the conversion.

Types

type Reader

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

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

func NewReader

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

NewReader initializes and returns a new Reader for the specified MMDB file. It loads metadata and sets default options for the reader.

func (*Reader) Close

func (r *Reader) Close() error

Close releases any resources used by the Reader and closes the MMDB 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 applies the provided option to the Reader's configuration.

type ReaderOption added in v0.2.1

type ReaderOption struct {
	DisableExtraData bool // If true, extra data (matched via GeoNameID) won't be used.
	UseFullField     bool // If true, all data will be combined into a single JSON string field.
}

ReaderOption contains configuration options for the Reader.

type Writer

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

Writer provides functionalities to write IP data into MMDB format.

func NewWriter

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

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

func (*Writer) ConvertMap added in v0.2.1

func (w *Writer) ConvertMap(fields, values []string) map[string]interface{}

ConvertMap converts fields and values to a map.

func (*Writer) Insert

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

Insert adds the given IP information into the writer.

func (*Writer) SetOption

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

SetOption sets the provided options to the Writer. Currently, it supports mmdbwriter.Options for the MMDB writer.

func (*Writer) WriteTo

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

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

type WriterOption

type WriterOption struct {
	SelectLanguages string // SelectLanguages specifies the languages to be selected for the names.
}

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