iplibrary

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: BSD-3-Clause Imports: 27 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultIPLibraryData added in v0.5.2

func DefaultIPLibraryData() []byte

func HashRegion added in v0.5.2

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

func InitDefault added in v0.5.2

func InitDefault() error

InitDefault 加载默认的IP库

func LookupIPSummaries added in v1.2.9

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 added in v1.0.0

type Encrypt struct {
}

func NewEncrypt added in v1.0.0

func NewEncrypt() *Encrypt

func (*Encrypt) Decode added in v1.0.0

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

func (*Encrypt) Encode added in v1.0.0

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

type FileReader

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

func NewFileDataReader added in v0.5.2

func NewFileDataReader(dataReader io.Reader, password string, readerVersion ReaderVersion) (*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 added in v0.5.2

func (this *FileReader) RawReader() ReaderInterface

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 added in v0.5.2

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

func NewIPLibrary added in v0.5.2

func NewIPLibrary() *IPLibrary

func NewIPLibraryWithReader added in v0.5.2

func NewIPLibraryWithReader(reader ReaderInterface) *IPLibrary

func (*IPLibrary) Destroy added in v1.0.0

func (this *IPLibrary) Destroy()

func (*IPLibrary) InitFromData added in v0.5.2

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

func (*IPLibrary) Lookup added in v0.5.2

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

func (*IPLibrary) LookupIP added in v0.5.2

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 added in v0.5.2

func Lookup(ip net.IP) *QueryResult

Lookup 查询IP信息

func LookupIP added in v0.5.2

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 added in v0.5.2

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 added in v0.5.2

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

func (*QueryResult) ProviderId

func (this *QueryResult) ProviderId() int64

func (*QueryResult) ProviderName

func (this *QueryResult) ProviderName() string

func (*QueryResult) ProvinceCodes added in v0.5.2

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

func (*QueryResult) ProvinceId

func (this *QueryResult) ProvinceId() int64

func (*QueryResult) ProvinceName

func (this *QueryResult) ProvinceName() string

func (*QueryResult) RegionSummary added in v1.2.9

func (this *QueryResult) RegionSummary() string

func (*QueryResult) Summary added in v0.5.2

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 NewReaderV1 added in v1.3.5

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

NewReaderV1 创建新Reader对象

func (*Reader) Destroy added in v1.0.0

func (this *Reader) Destroy()

func (*Reader) IPv4Items

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

func (*Reader) IPv6Items

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

func (*Reader) Lookup

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

func (*Reader) Meta

func (this *Reader) Meta() *Meta

type ReaderInterface added in v1.3.5

type ReaderInterface interface {
	Meta() *Meta
	Lookup(ip net.IP) *QueryResult
	Destroy()
}

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 ReaderV2 added in v1.3.5

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

ReaderV2 IP库Reader V2

func NewReaderV2 added in v1.3.5

func NewReaderV2(reader io.Reader) (*ReaderV2, error)

NewReaderV2 创建新Reader对象

func (*ReaderV2) Destroy added in v1.3.5

func (this *ReaderV2) Destroy()

func (*ReaderV2) IPv4Items added in v1.3.5

func (this *ReaderV2) IPv4Items() []ipv4ItemV2

func (*ReaderV2) IPv6Items added in v1.3.5

func (this *ReaderV2) IPv6Items() []ipv6ItemV2

func (*ReaderV2) Lookup added in v1.3.5

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

func (*ReaderV2) Meta added in v1.3.5

func (this *ReaderV2) Meta() *Meta

type ReaderVersion added in v1.3.5

type ReaderVersion = int
const (
	ReaderVersionV1 ReaderVersion = 0
	ReaderVersionV2 ReaderVersion = 2
)

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 added in v0.5.2

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

func NewUpdater added in v0.5.2

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

func (*Updater) Init added in v0.5.2

func (this *Updater) Init() error

func (*Updater) Loop added in v0.5.2

func (this *Updater) Loop() error

func (*Updater) Start added in v0.5.2

func (this *Updater) Start()

type UpdaterSource added in v0.5.2

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 WriterInterface added in v1.3.5

type WriterInterface interface {
	WriteMeta() error
	Write(ipFrom string, ipTo string, countryId int64, provinceId int64, cityId int64, townId int64, providerId int64) error
	Sum() string
}

type WriterV1 added in v1.3.5

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

func NewWriterV1 added in v1.3.5

func NewWriterV1(writer io.Writer, meta *Meta) *WriterV1

func (*WriterV1) Sum added in v1.3.5

func (this *WriterV1) Sum() string

func (*WriterV1) Write added in v1.3.5

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

func (*WriterV1) WriteMeta added in v1.3.5

func (this *WriterV1) WriteMeta() error

type WriterV2 added in v1.3.5

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

func NewWriterV2 added in v1.3.5

func NewWriterV2(writer io.Writer, meta *Meta) *WriterV2

func (*WriterV2) Sum added in v1.3.5

func (this *WriterV2) Sum() string

func (*WriterV2) Write added in v1.3.5

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

func (*WriterV2) WriteMeta added in v1.3.5

func (this *WriterV2) WriteMeta() error

Jump to

Keyboard shortcuts

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