mmdb

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// FieldCity 城市
	FieldCity = "city"

	// FieldContinent 大洲
	FieldContinent = "continent"

	// FieldContinentCode 大洲代码
	FieldContinentCode = "continent_code"

	// FieldCountry 国家
	FieldCountry = "country"

	// FieldCountryISOCode 国家ISO代码
	FieldCountryISOCode = "country_iso_code"

	// FieldCountryIsInEuropeanUnion 国家是否在欧盟
	FieldCountryIsInEuropeanUnion = "country_is_in_european_union"

	// 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"

	// FieldRegisteredCountryISOCode 注册国家ISO代码
	FieldRegisteredCountryISOCode = "registered_country_iso_code"

	// FieldRegisteredCountryIsInEuropeanUnion 注册国家是否在欧盟
	FieldRegisteredCountryIsInEuropeanUnion = "registered_country_is_in_european_union"

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

	// FieldRepresentedCountryISOCode 代表国家ISO代码
	FieldRepresentedCountryISOCode = "represented_country_iso_code"

	// FieldRepresentedCountryIsInEuropeanUnion 代表国家是否在欧盟
	FieldRepresentedCountryIsInEuropeanUnion = "represented_country_is_in_european_union"

	// 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

ASNFullFields ASN数据库全字段列表

CityFullFields 城市数据库全字段列表

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

View Source
var Lang = "zh-CN"

Functions

func ConvertMap

func ConvertMap(fields, values []string) mmdbtype.DataType

ConvertMap converts fields and values to mmdbtype.Map FIXME temporary solution :)

Types

type ASN

type ASN struct {
	AutonomousSystemNumber       uint   `maxminddb:"autonomous_system_number"`
	AutonomousSystemOrganization string `maxminddb:"autonomous_system_organization"`
}

The ASN struct corresponds to the data in the GeoLite2 ASN database.

func (*ASN) Format

func (a *ASN) Format() map[string]string

type AnonymousIP

type AnonymousIP struct {
	IsAnonymous        bool `maxminddb:"is_anonymous"`
	IsAnonymousVPN     bool `maxminddb:"is_anonymous_vpn"`
	IsHostingProvider  bool `maxminddb:"is_hosting_provider"`
	IsPublicProxy      bool `maxminddb:"is_public_proxy"`
	IsResidentialProxy bool `maxminddb:"is_residential_proxy"`
	IsTorExitNode      bool `maxminddb:"is_tor_exit_node"`
}

The AnonymousIP struct corresponds to the data in the GeoIP2 Anonymous IP database.

type City

type City struct {
	City struct {
		GeoNameID uint              `maxminddb:"geoname_id"`
		Names     map[string]string `maxminddb:"names"`
	} `maxminddb:"city"`
	Continent struct {
		Code      string            `maxminddb:"code"`
		GeoNameID uint              `maxminddb:"geoname_id"`
		Names     map[string]string `maxminddb:"names"`
	} `maxminddb:"continent"`
	Country struct {
		GeoNameID         uint              `maxminddb:"geoname_id"`
		IsInEuropeanUnion bool              `maxminddb:"is_in_european_union"`
		IsoCode           string            `maxminddb:"iso_code"`
		Names             map[string]string `maxminddb:"names"`
	} `maxminddb:"country"`
	Location struct {
		AccuracyRadius uint16  `maxminddb:"accuracy_radius"`
		Latitude       float64 `maxminddb:"latitude"`
		Longitude      float64 `maxminddb:"longitude"`
		MetroCode      uint    `maxminddb:"metro_code"`
		TimeZone       string  `maxminddb:"time_zone"`
	} `maxminddb:"location"`
	Postal struct {
		Code string `maxminddb:"code"`
	} `maxminddb:"postal"`
	RegisteredCountry struct {
		GeoNameID         uint              `maxminddb:"geoname_id"`
		IsInEuropeanUnion bool              `maxminddb:"is_in_european_union"`
		IsoCode           string            `maxminddb:"iso_code"`
		Names             map[string]string `maxminddb:"names"`
	} `maxminddb:"registered_country"`
	RepresentedCountry struct {
		GeoNameID         uint              `maxminddb:"geoname_id"`
		IsInEuropeanUnion bool              `maxminddb:"is_in_european_union"`
		IsoCode           string            `maxminddb:"iso_code"`
		Names             map[string]string `maxminddb:"names"`
		Type              string            `maxminddb:"type"`
	} `maxminddb:"represented_country"`
	Subdivisions []struct {
		GeoNameID uint              `maxminddb:"geoname_id"`
		IsoCode   string            `maxminddb:"iso_code"`
		Names     map[string]string `maxminddb:"names"`
	} `maxminddb:"subdivisions"`
	Traits struct {
		IsAnonymousProxy    bool `maxminddb:"is_anonymous_proxy"`
		IsSatelliteProvider bool `maxminddb:"is_satellite_provider"`
	} `maxminddb:"traits"`
}

The City struct corresponds to the data in the GeoIP2/GeoLite2 City databases.

func (*City) Format

func (c *City) Format() map[string]string

type ConnectionType

type ConnectionType struct {
	ConnectionType string `maxminddb:"connection_type"`
}

The ConnectionType struct corresponds to the data in the GeoIP2 Connection-Type database.

type Country

type Country struct {
	Continent struct {
		Code      string            `maxminddb:"code"`
		GeoNameID uint              `maxminddb:"geoname_id"`
		Names     map[string]string `maxminddb:"names"`
	} `maxminddb:"continent"`
	Country struct {
		GeoNameID         uint              `maxminddb:"geoname_id"`
		IsInEuropeanUnion bool              `maxminddb:"is_in_european_union"`
		IsoCode           string            `maxminddb:"iso_code"`
		Names             map[string]string `maxminddb:"names"`
	} `maxminddb:"country"`
	RegisteredCountry struct {
		GeoNameID         uint              `maxminddb:"geoname_id"`
		IsInEuropeanUnion bool              `maxminddb:"is_in_european_union"`
		IsoCode           string            `maxminddb:"iso_code"`
		Names             map[string]string `maxminddb:"names"`
	} `maxminddb:"registered_country"`
	RepresentedCountry struct {
		GeoNameID         uint              `maxminddb:"geoname_id"`
		IsInEuropeanUnion bool              `maxminddb:"is_in_european_union"`
		IsoCode           string            `maxminddb:"iso_code"`
		Names             map[string]string `maxminddb:"names"`
		Type              string            `maxminddb:"type"`
	} `maxminddb:"represented_country"`
	Traits struct {
		IsAnonymousProxy    bool `maxminddb:"is_anonymous_proxy"`
		IsSatelliteProvider bool `maxminddb:"is_satellite_provider"`
	} `maxminddb:"traits"`
}

The Country struct corresponds to the data in the GeoIP2/GeoLite2 Country databases.

type Domain

type Domain struct {
	Domain string `maxminddb:"domain"`
}

The Domain struct corresponds to the data in the GeoIP2 Domain database.

type Enterprise

type Enterprise struct {
	City struct {
		Confidence uint8             `maxminddb:"confidence"`
		GeoNameID  uint              `maxminddb:"geoname_id"`
		Names      map[string]string `maxminddb:"names"`
	} `maxminddb:"city"`
	Continent struct {
		Code      string            `maxminddb:"code"`
		GeoNameID uint              `maxminddb:"geoname_id"`
		Names     map[string]string `maxminddb:"names"`
	} `maxminddb:"continent"`
	Country struct {
		GeoNameID         uint              `maxminddb:"geoname_id"`
		IsoCode           string            `maxminddb:"iso_code"`
		Names             map[string]string `maxminddb:"names"`
		Confidence        uint8             `maxminddb:"confidence"`
		IsInEuropeanUnion bool              `maxminddb:"is_in_european_union"`
	} `maxminddb:"country"`
	Location struct {
		AccuracyRadius uint16  `maxminddb:"accuracy_radius"`
		Latitude       float64 `maxminddb:"latitude"`
		Longitude      float64 `maxminddb:"longitude"`
		MetroCode      uint    `maxminddb:"metro_code"`
		TimeZone       string  `maxminddb:"time_zone"`
	} `maxminddb:"location"`
	Postal struct {
		Code       string `maxminddb:"code"`
		Confidence uint8  `maxminddb:"confidence"`
	} `maxminddb:"postal"`
	RegisteredCountry struct {
		GeoNameID         uint              `maxminddb:"geoname_id"`
		IsoCode           string            `maxminddb:"iso_code"`
		Names             map[string]string `maxminddb:"names"`
		Confidence        uint8             `maxminddb:"confidence"`
		IsInEuropeanUnion bool              `maxminddb:"is_in_european_union"`
	} `maxminddb:"registered_country"`
	RepresentedCountry struct {
		GeoNameID         uint              `maxminddb:"geoname_id"`
		IsInEuropeanUnion bool              `maxminddb:"is_in_european_union"`
		IsoCode           string            `maxminddb:"iso_code"`
		Names             map[string]string `maxminddb:"names"`
		Type              string            `maxminddb:"type"`
	} `maxminddb:"represented_country"`
	Subdivisions []struct {
		Confidence uint8             `maxminddb:"confidence"`
		GeoNameID  uint              `maxminddb:"geoname_id"`
		IsoCode    string            `maxminddb:"iso_code"`
		Names      map[string]string `maxminddb:"names"`
	} `maxminddb:"subdivisions"`
	Traits struct {
		AutonomousSystemNumber       uint    `maxminddb:"autonomous_system_number"`
		AutonomousSystemOrganization string  `maxminddb:"autonomous_system_organization"`
		ConnectionType               string  `maxminddb:"connection_type"`
		Domain                       string  `maxminddb:"domain"`
		IsAnonymousProxy             bool    `maxminddb:"is_anonymous_proxy"`
		IsLegitimateProxy            bool    `maxminddb:"is_legitimate_proxy"`
		IsSatelliteProvider          bool    `maxminddb:"is_satellite_provider"`
		ISP                          string  `maxminddb:"isp"`
		MobileCountryCode            string  `maxminddb:"mobile_country_code"`
		MobileNetworkCode            string  `maxminddb:"mobile_network_code"`
		Organization                 string  `maxminddb:"organization"`
		StaticIPScore                float64 `maxminddb:"static_ip_score"`
		UserType                     string  `maxminddb:"user_type"`
	} `maxminddb:"traits"`
}

The Enterprise struct corresponds to the data in the GeoIP2 Enterprise database.

type ISP

type ISP struct {
	AutonomousSystemNumber       uint   `maxminddb:"autonomous_system_number"`
	AutonomousSystemOrganization string `maxminddb:"autonomous_system_organization"`
	ISP                          string `maxminddb:"isp"`
	MobileCountryCode            string `maxminddb:"mobile_country_code"`
	MobileNetworkCode            string `maxminddb:"mobile_network_code"`
	Organization                 string `maxminddb:"organization"`
}

The ISP struct corresponds to the data in the GeoIP2 ISP database.

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 a new instance of Reader.

func (*Reader) Close

func (d *Reader) Close() error

Close closes the IP database.

func (*Reader) Find

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

Find retrieves IP information based on the given IP address.

func (*Reader) Meta

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

Meta returns the meta-information of the IP database.

func (*Reader) SetOption

func (d *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 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) 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 {
}

WriterOption provides options for the Writer.

Jump to

Keyboard shortcuts

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