ipdb

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ipdb provides local IP database lookups.

Index

Constants

View Source
const (
	DriverIP2Region   = "ip2region"
	DriverMaxMind     = "maxmind"
	DriverMaxMindCity = "maxmind-city"
	DriverMaxMindASN  = "maxmind-asn"
)
View Source
const (
	IP2RegionModeFile        = "file"
	IP2RegionModeVectorIndex = "vector_index"
	IP2RegionModeMemory      = "memory"
)

Variables

View Source
var (
	ErrInvalidConfig     = errors.New("ipdb: invalid config")
	ErrInvalidIP         = errors.New("ipdb: invalid ip")
	ErrUnsupportedDriver = errors.New("ipdb: unsupported driver")
	ErrClosed            = errors.New("ipdb: locator closed")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Driver string

	// Path is used by ip2region, maxmind-city and maxmind-asn.
	Path string

	// CityPath and ASNPath are used by DriverMaxMind to merge City and ASN records.
	CityPath string
	ASNPath  string

	// Language selects localized names from MaxMind databases.
	Language string

	// Mode controls ip2region loading strategy: file, vector_index or memory.
	Mode string

	// Hooks observe lookup results. Hook failures must be handled by the hook itself.
	Hooks []Hook
}

type Hook

type Hook interface {
	AfterLookup(ctx context.Context, event LookupEvent)
}

type HookFunc

type HookFunc func(ctx context.Context, event LookupEvent)

func (HookFunc) AfterLookup

func (f HookFunc) AfterLookup(ctx context.Context, event LookupEvent)

type Locator

type Locator interface {
	Lookup(ctx context.Context, ip string) (*Record, error)
	Close() error
}

func New

func New(cfg Config) (Locator, error)

type LookupEvent

type LookupEvent struct {
	IP     string
	Record *Record
	Err    error
}

type Record

type Record struct {
	IP      string `json:"ip,omitempty"`
	Version int    `json:"version,omitempty"`
	Source  string `json:"source,omitempty"`

	Continent     string `json:"continent,omitempty"`
	ContinentCode string `json:"continent_code,omitempty"`

	Country     string `json:"country,omitempty"`
	CountryCode string `json:"country_code,omitempty"`

	Region     string `json:"region,omitempty"`
	RegionCode string `json:"region_code,omitempty"`
	Province   string `json:"province,omitempty"`
	City       string `json:"city,omitempty"`
	District   string `json:"district,omitempty"`
	PostalCode string `json:"postal_code,omitempty"`
	TimeZone   string `json:"time_zone,omitempty"`

	ISP            string `json:"isp,omitempty"`
	ASN            string `json:"asn,omitempty"`
	ASNumber       uint   `json:"as_number,omitempty"`
	ASOrganization string `json:"as_organization,omitempty"`

	Latitude  *float64 `json:"latitude,omitempty"`
	Longitude *float64 `json:"longitude,omitempty"`

	Network               string `json:"network,omitempty"`
	RegisteredCountry     string `json:"registered_country,omitempty"`
	RegisteredCountryCode string `json:"registered_country_code,omitempty"`
}

func (*Record) HasData

func (r *Record) HasData() bool

Jump to

Keyboard shortcuts

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