geoip

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package geoip 提供容器管理的离线IP查询、数据库状态、原子更新和自定义解析器。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultSources added in v0.1.3

func DefaultSources() map[string]string

DefaultSources 可在配置中替换为自建镜像;五类文件独立验证和更新。

func Update

func Update(ctx context.Context) error

Types

type Config added in v0.1.3

type Config struct {
	Enabled   bool
	Directory string
	Sources   map[string]string
}

type Manager added in v0.1.3

type Manager struct {
	Config Config
	Client *http.Client
	// contains filtered or unexported fields
}

func ManagerFrom added in v0.1.3

func ManagerFrom(r cc.Resolver) (*Manager, error)

ManagerFrom 返回当前应用的共享实例;应用退出时由容器关闭。

func New added in v0.1.3

func New(cfg Config) *Manager

New 只打开本地数据库,不自动联网;后台定时重载其他进程更新的文件。

func Resolve added in v0.1.3

func Resolve() *Manager

func (*Manager) Close added in v0.1.3

func (m *Manager) Close() error

func (*Manager) Extend added in v0.1.3

func (m *Manager) Extend(resolver Resolver)

Extend 在内置解析完成后补充或覆盖字段,不允许解析器保留Result指针。

func (*Manager) Lookup added in v0.1.3

func (m *Manager) Lookup(ctx context.Context, ip string) (Result, error)

func (*Manager) Reload added in v0.1.3

func (m *Manager) Reload() error

func (*Manager) Status added in v0.1.3

func (m *Manager) Status() []Status

func (*Manager) Update added in v0.1.3

func (m *Manager) Update(ctx context.Context) error

type Resolver added in v0.1.3

type Resolver func(context.Context, netip.Addr, *Result) error

type Result added in v0.1.3

type Result struct {
	IP             string            `json:"ip"`
	CountryCode    string            `json:"country_code"`
	Country        string            `json:"country"`
	Province       string            `json:"province"`
	City           string            `json:"city"`
	ISP            string            `json:"isp"`
	ASN            uint              `json:"asn"`
	Organization   string            `json:"organization"`
	TimeZone       string            `json:"time_zone"`
	Latitude       float64           `json:"latitude"`
	Longitude      float64           `json:"longitude"`
	AccuracyRadius uint              `json:"accuracy_radius"`
	Location       string            `json:"location"`
	Public         bool              `json:"public"`
	Sources        map[string]string `json:"sources"`
}

func Lookup

func Lookup(ctx context.Context, ip string) (Result, error)

type Status added in v0.1.3

type Status struct {
	Name      string `json:"name"`
	Size      int64  `json:"size"`
	UpdatedAt int64  `json:"updated_at"`
	Ready     bool   `json:"ready"`
	Error     string `json:"error,omitempty"`
}

Jump to

Keyboard shortcuts

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