iplibrary

package
v0.5.8 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: BSD-3-Clause Imports: 21 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 uint32, provinceId uint32, cityId uint32, townId uint32, providerId uint32) string

func InitDefault added in v0.5.2

func InitDefault() error

Types

type City

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

type Country

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

type FileReader

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

func NewFileDataReader added in v0.5.2

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

func NewFileReader

func NewFileReader(path 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() *Reader

type FileWriter

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

func NewFileWriter

func NewFileWriter(path string, meta *Meta) (*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 *Reader) *IPLibrary

func (*IPLibrary) InitFromData added in v0.5.2

func (this *IPLibrary) InitFromData(data []byte) 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 uint32) *Country

func (*Meta) Init

func (this *Meta) Init()

func (*Meta) ProviderWithId

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

func (*Meta) ProvinceWithId

func (this *Meta) ProvinceWithId(provinceId uint32) *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    uint32   `json:"id"`
	Name  string   `json:"name"`
	Codes []string `json:"codes"`
}

type Province

type Province struct {
	Id    uint32   `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

func LookupIP added in v0.5.2

func LookupIP(ip string) *QueryResult

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) 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
}

func NewReader

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

func (*Reader) IPv4Items

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

func (*Reader) IPv6Items

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

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 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
)

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