Documentation
¶
Index ¶
Constants ¶
const ( // Country 国家 Country = "country" // Province 省份 Province = "province" // City 城市 City = "city" // ISP 运营商 ISP = "isp" // ASN 自治域号 ASN = "asn" // Continent 大洲 Continent = "continent" // UTCOffset UTC 偏移值 UTCOffset = "utcOffset" // Latitude 纬度 Latitude = "latitude" // Longitude 经度 Longitude = "longitude" // ChinaAdminCode 中国行政区划代码 ChinaAdminCode = "chinaAdminCode" )
const ( // IPv4 represents the version for IPv4 IP database. IPv4 = 1 // IPv6 represents the version for IPv6 IP database. IPv6 = 2 // MetaVersion represents the version of the metadata. MetaVersion = 1 )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type IPInfo ¶
type IPInfo struct { // IP represents the IP address. IP net.IP // IPNet denotes the network range to which the IP belongs. IPNet *ipnet.Range // Data holds the actual information related to the IP in a key-value format. Data map[string]string // FieldAlias maps common field names to their corresponding database field names. FieldAlias map[string]string // Fields lists the fields that should be output. Fields []string // ReplaceFields specifies fields that should be replaced with specific values. // operate.FieldSelector use this to replace the value of the field. ReplaceFields map[string]string }
IPInfo represents information related to a specific IP address.
func (*IPInfo) AddCommonFieldAlias ¶
AddCommonFieldAlias adds common field aliases to the FieldAlias map. It maps a database-specific field name to a common field name.
func (*IPInfo) GetData ¶
GetData retrieves the data for the given field. It first checks if the field exists in the Data map directly. If not, it checks the FieldAlias map to determine the corresponding database field and retrieves the value. Returns the value and a boolean indicating if the field was found.
func (*IPInfo) Output ¶
func (i *IPInfo) Output(dbFiled bool) *IPInfoOutput
Output constructs and returns an IPInfoOutput based on the current IPInfo. It decides whether to use the database field or the common field based on the dbFiled flag.
type IPInfoOutput ¶
type IPInfoOutput struct { IP string `json:"ip"` Net string `json:"net"` Data map[string]string `json:"data"` }
IPInfoOutput represents the structure for outputting IP information.
type Meta ¶
type Meta struct { // MetaVersion indicates the version of the metadata. MetaVersion int // Format represents the data format of the IP database. Format string // IPVersion indicates the version of the IP database (IPv4 or IPv6). IPVersion int // Fields lists the data fields available in the IP database. Fields []string // FieldAlias maps common field names to database-specific field names. FieldAlias map[string]string }
Meta represents the metadata for the IP database.
func (*Meta) AddCommonFieldAlias ¶
AddCommonFieldAlias adds aliases for common fields to the metadata. It checks if the provided database field exists in the metadata's fields.
func (*Meta) IsIPv4Support ¶
IsIPv4Support checks if the metadata supports IPv4.
func (*Meta) IsIPv6Support ¶
IsIPv6Support checks if the metadata supports IPv6.
func (*Meta) SupportFields ¶
SupportFields returns a map of fields that are supported by the metadata. It includes both the original fields and the alias fields.