model

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2023 License: Apache-2.0 Imports: 6 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 AlfredIcon added in v0.2.7

type AlfredIcon struct {
	Type string `json:"type"`
	Path string `json:"path"`
}

AlfredIcon represents the icon for an AlfredItem.

type AlfredItem added in v0.2.7

type AlfredItem struct {
	Title    string     `json:"title"`
	Subtitle string     `json:"subtitle"`
	Arg      string     `json:"arg"`
	Icon     AlfredIcon `json:"icon"`
	Valid    bool       `json:"valid"`
	Text     AlfredText `json:"text"`
}

AlfredItem represents an item to be displayed in Alfred's result list.

type AlfredText added in v0.2.7

type AlfredText struct {
	Copy string `json:"copy"`
}

AlfredText provides additional text information for an AlfredItem.

type DataList added in v0.2.7

type DataList struct {
	Items   []interface{} `json:"items,omitempty"`
	Domains []interface{} `json:"domains,omitempty"`
}

DataList holds a list of items to be displayed in Alfred's result list.

func (*DataList) AddAlfredItemByDomainInfo added in v0.2.8

func (d *DataList) AddAlfredItemByDomainInfo(info *DomainInfo)

AddAlfredItemByDomainInfo creates an AlfredItem from the provided DomainInfo and adds it to the DataList.

func (*DataList) AddAlfredItemByIPInfo added in v0.2.7

func (d *DataList) AddAlfredItemByIPInfo(info *IPInfo)

AddAlfredItemByIPInfo creates an AlfredItem from the provided IPInfo and adds it to the DataList.

func (*DataList) AddAlfredItemEmpty added in v0.2.7

func (d *DataList) AddAlfredItemEmpty()

AddAlfredItemEmpty adds a default "Not found" AlfredItem to the DataList if the list is empty.

func (*DataList) AddDomain added in v0.3.0

func (d *DataList) AddDomain(domain interface{})

AddDomain appends a new item to the DataList's Domains slice.

func (*DataList) AddItem added in v0.2.7

func (d *DataList) AddItem(item interface{})

AddItem appends a new item to the DataList's Items slice.

type DomainInfo added in v0.2.5

type DomainInfo struct {

	// Domain is the domain name.
	Domain string `json:"domain"`

	// MainDomain is the main domain name.
	MainDomain string `json:"main_domain"`

	// Data holds the actual information related to the domain.
	Data map[string]string `json:"data"`
}

DomainInfo holds details about a specific domain, including its name, main domain, and associated data.

func (*DomainInfo) Values added in v0.2.8

func (d *DomainInfo) Values() []string

Values extracts the values from the Data map, sorts them alphabetically, and returns them as a slice of strings. If the DomainInfo receiver or its Data map is nil, it returns nil to indicate the absence of data.

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