model

package
v0.2.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
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"
)
View Source
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

func ConvertToDBFields

func ConvertToDBFields(fields []string, readerFieldAlias, writerFieldAlias map[string]string) []string

ConvertToDBFields converts field names from a reader database's alias to a writer database's alias.

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

func (i *IPInfo) AddCommonFieldAlias(fieldAlias map[string]string)

AddCommonFieldAlias adds common field aliases to the FieldAlias map. It maps a database-specific field name to a common field name.

func (*IPInfo) GetData

func (i *IPInfo) GetData(field string) (string, bool)

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.

func (*IPInfo) Values

func (i *IPInfo) Values() []string

Values returns a slice of data values based on the Fields slice. It also considers any replacements specified in the ReplaceFields map.

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

func (m *Meta) AddCommonFieldAlias(fieldAlias map[string]string)

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

func (m *Meta) IsIPv4Support() bool

IsIPv4Support checks if the metadata supports IPv4.

func (*Meta) IsIPv6Support

func (m *Meta) IsIPv6Support() bool

IsIPv6Support checks if the metadata supports IPv6.

func (*Meta) SupportFields

func (m *Meta) SupportFields() map[string]bool

SupportFields returns a map of fields that are supported by the metadata. It includes both the original fields and the alias fields.

Jump to

Keyboard shortcuts

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