iplibrary

package
v0.0.0-...-5008076 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultIPLibraryData

func DefaultIPLibraryData() []byte

func HashRegion

func HashRegion(countryId uint16, provinceId uint16, cityId uint32, townId uint32, providerId uint16) string

func InitDefault

func InitDefault() error

InitDefault 加载默认的IP库

func LookupIPSummaries

func LookupIPSummaries(ipList []string) map[string]string

LookupIPSummaries 查询一组IP对应的区域描述

Types

type City

type City struct {
	Id    uint32   `json:"id"`
	Name  string   `json:"name"`
	Codes []string `json:"codes"`
}

type Country

type Country struct {
	Id    uint16   `json:"id"`
	Name  string   `json:"name"`
	Codes []string `json:"codes"`
}

type Encrypt

type Encrypt struct {
}

func NewEncrypt

func NewEncrypt() *Encrypt

func (*Encrypt) Decode

func (this *Encrypt) Decode(encodedData []byte, password string) ([]byte, error)

func (*Encrypt) Encode

func (this *Encrypt) Encode(srcData []byte, password string) ([]byte, error)

type FileReader

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

func NewFileDataReader

func NewFileDataReader(dataReader io.Reader, password string) (*FileReader, error)

func NewFileReader

func NewFileReader(path string, password string) (*FileReader, error)

func (*FileReader) Lookup

func (this *FileReader) Lookup(ip net.IP) *QueryResult

func (*FileReader) Meta

func (this *FileReader) Meta() *Meta

func (*FileReader) RawReader

func (this *FileReader) RawReader() *Reader

type FileWriter

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

func NewFileWriter

func NewFileWriter(path string, meta *Meta, password string) (*FileWriter, error)

func (*FileWriter) Close

func (this *FileWriter) Close() error

func (*FileWriter) Sum

func (this *FileWriter) Sum() string

func (*FileWriter) Write

func (this *FileWriter) Write(ipFrom string, ipTo string, countryId int64, provinceId int64, cityId int64, townId int64, providerId int64) error

func (*FileWriter) WriteMeta

func (this *FileWriter) WriteMeta() error

type IPLibrary

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

func NewIPLibrary

func NewIPLibrary() *IPLibrary

func NewIPLibraryWithReader

func NewIPLibraryWithReader(reader *Reader) *IPLibrary

func (*IPLibrary) Destroy

func (this *IPLibrary) Destroy()

func (*IPLibrary) InitFromData

func (this *IPLibrary) InitFromData(data []byte, password string) error

func (*IPLibrary) Lookup

func (this *IPLibrary) Lookup(ip net.IP) *QueryResult

func (*IPLibrary) LookupIP

func (this *IPLibrary) LookupIP(ip string) *QueryResult

type Meta

type Meta struct {
	Version   int         `json:"version"` // IP库版本
	Code      string      `json:"code"`    // 代号,用来区分不同的IP库
	Author    string      `json:"author"`
	Countries []*Country  `json:"countries"`
	Provinces []*Province `json:"provinces"`
	Cities    []*City     `json:"cities"`
	Towns     []*Town     `json:"towns"`
	Providers []*Provider `json:"providers"`
	CreatedAt int64       `json:"createdAt"`
	// contains filtered or unexported fields
}

func (*Meta) CityWithId

func (this *Meta) CityWithId(cityId uint32) *City

func (*Meta) CountryWithId

func (this *Meta) CountryWithId(countryId uint16) *Country

func (*Meta) Init

func (this *Meta) Init()

func (*Meta) ProviderWithId

func (this *Meta) ProviderWithId(providerId uint16) *Provider

func (*Meta) ProvinceWithId

func (this *Meta) ProvinceWithId(provinceId uint16) *Province

func (*Meta) TownWithId

func (this *Meta) TownWithId(townId uint32) *Town

type Parser

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

func NewParser

func NewParser(config *ParserConfig) (*Parser, error)

func (*Parser) Parse

func (this *Parser) Parse() error

func (*Parser) Write

func (this *Parser) Write(data []byte)

type ParserConfig

type ParserConfig struct {
	Template    *Template
	EmptyValues []string
	Iterator    func(values map[string]string) error
}

type Provider

type Provider struct {
	Id    uint16   `json:"id"`
	Name  string   `json:"name"`
	Codes []string `json:"codes"`
}

type Province

type Province struct {
	Id    uint16   `json:"id"`
	Name  string   `json:"name"`
	Codes []string `json:"codes"`
}

type QueryResult

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

func Lookup

func Lookup(ip net.IP) *QueryResult

Lookup 查询IP信息

func LookupIP

func LookupIP(ip string) *QueryResult

LookupIP 查询IP信息

func (*QueryResult) CityId

func (this *QueryResult) CityId() int64

func (*QueryResult) CityName

func (this *QueryResult) CityName() string

func (*QueryResult) CountryCodes

func (this *QueryResult) CountryCodes() []string

func (*QueryResult) CountryId

func (this *QueryResult) CountryId() int64

func (*QueryResult) CountryName

func (this *QueryResult) CountryName() string

func (*QueryResult) IsOk

func (this *QueryResult) IsOk() bool

func (*QueryResult) ProviderCodes

func (this *QueryResult) ProviderCodes() []string

func (*QueryResult) ProviderId

func (this *QueryResult) ProviderId() int64

func (*QueryResult) ProviderName

func (this *QueryResult) ProviderName() string

func (*QueryResult) ProvinceCodes

func (this *QueryResult) ProvinceCodes() []string

func (*QueryResult) ProvinceId

func (this *QueryResult) ProvinceId() int64

func (*QueryResult) ProvinceName

func (this *QueryResult) ProvinceName() string

func (*QueryResult) RegionSummary

func (this *QueryResult) RegionSummary() string

func (*QueryResult) Summary

func (this *QueryResult) Summary() string

func (*QueryResult) TownId

func (this *QueryResult) TownId() int64

func (*QueryResult) TownName

func (this *QueryResult) TownName() string

type Reader

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

Reader IP库Reader

func NewReader

func NewReader(reader io.Reader) (*Reader, error)

NewReader 创建新Reader对象

func (*Reader) Destroy

func (this *Reader) Destroy()

func (*Reader) IPv4Items

func (this *Reader) IPv4Items() []*ipv4Item

func (*Reader) IPv6Items

func (this *Reader) IPv6Items() []*ipv6Item

func (*Reader) Lookup

func (this *Reader) Lookup(ip net.IP) *QueryResult

func (*Reader) Meta

func (this *Reader) Meta() *Meta

type ReaderParser

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

func NewReaderParser

func NewReaderParser(reader io.Reader, config *ParserConfig) (*ReaderParser, error)

func (*ReaderParser) Parse

func (this *ReaderParser) Parse() error

type Template

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

func NewTemplate

func NewTemplate(templateString string) (*Template, error)

func (*Template) Extract

func (this *Template) Extract(text string, emptyValues []string) (values map[string]string, ok bool)

type Town

type Town struct {
	Id    uint32   `json:"id"`
	Name  string   `json:"name"`
	Codes []string `json:"codes"`
}

type Updater

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

func NewUpdater

func NewUpdater(source UpdaterSource, interval time.Duration) *Updater

func (*Updater) Init

func (this *Updater) Init() error

func (*Updater) Loop

func (this *Updater) Loop() error

func (*Updater) Start

func (this *Updater) Start()

type UpdaterSource

type UpdaterSource interface {
	// DataDir 文件目录
	DataDir() string

	// FindLatestFile 检查最新的IP库文件
	FindLatestFile() (code string, fileId int64, err error)

	// DownloadFile 下载文件
	DownloadFile(fileId int64, writer io.Writer) error

	// LogInfo 普通日志
	LogInfo(message string)

	// LogError 错误日志
	LogError(err error)
}

type Version

type Version = int
const (
	Version1 Version = 1
	Version2 Version = 2 // 主要变更为数字使用32进制
)

type Writer

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

func NewWriter

func NewWriter(writer io.Writer, meta *Meta) *Writer

func (*Writer) Sum

func (this *Writer) Sum() string

func (*Writer) Write

func (this *Writer) Write(ipFrom string, ipTo string, countryId int64, provinceId int64, cityId int64, townId int64, providerId int64) error

func (*Writer) WriteMeta

func (this *Writer) WriteMeta() error

Jump to

Keyboard shortcuts

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