geoip

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0, BSD-3-Clause, MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ASNURL     = "https://cdn.jsdelivr.net/npm/@ip-location-db/asn-mmdb/asn.mmdb"
	CountryURL = "https://cdn.jsdelivr.net/npm/@ip-location-db/geo-whois-asn-country-mmdb/geo-whois-asn-country.mmdb"
	CityURL    = "https://cdn.jsdelivr.net/npm/@ip-location-db/dbip-city-mmdb/dbip-city-ipv4.mmdb"
	// WHOIS database per AI.md PART 20
	WhoisURL = "https://cdn.jsdelivr.net/npm/@ip-location-db/geo-whois-asn-country-mmdb/geo-whois-asn-country.mmdb"
)

Database URLs from sapics/ip-location-db (NON-NEGOTIABLE per AI.md)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Enabled          bool     `yaml:"enabled"`
	Dir              string   `yaml:"dir"`
	Update           string   `yaml:"update"` // never, daily, weekly, monthly
	DenyCountries    []string `yaml:"deny_countries"`
	AllowedCountries []string `yaml:"allowed_countries"`
	// Database toggles
	ASN     bool `yaml:"asn"`
	Country bool `yaml:"country"`
	City    bool `yaml:"city"`
	WHOIS   bool `yaml:"whois"` // Enable WHOIS registrant data (per AI.md PART 20)
}

Config holds GeoIP configuration

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns default GeoIP configuration Per AI.md PART 20: GeoIP dir is {config_dir}/security/geoip

type Country

type Country struct {
	Code      string `json:"code"`
	Name      string `json:"name"`
	Continent string `json:"continent"`
}

Country represents country information

type Lookup

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

Lookup represents a GeoIP lookup service using MMDB format

func NewLookup

func NewLookup(cfg *Config) *Lookup

NewLookup creates a new GeoIP lookup service

func (*Lookup) Close

func (l *Lookup) Close()

Close closes all database connections

func (*Lookup) GetCountry

func (l *Lookup) GetCountry(code string) *Country

GetCountry returns country info by code

func (*Lookup) IsAllowed

func (l *Lookup) IsAllowed(ipStr string, allowedCountries []string) bool

IsAllowed checks if an IP is from an allowed country

func (*Lookup) IsBlocked

func (l *Lookup) IsBlocked(ipStr string, blockedCountries []string) bool

IsBlocked checks if an IP is from a blocked country

func (*Lookup) IsLoaded

func (l *Lookup) IsLoaded() bool

IsLoaded returns true if database is loaded

func (*Lookup) LastUpdate

func (l *Lookup) LastUpdate() time.Time

LastUpdate returns the last update time

func (*Lookup) LoadDatabase

func (l *Lookup) LoadDatabase(path string) error

LoadDatabase loads a database from path (for backwards compatibility)

func (*Lookup) LoadDatabases

func (l *Lookup) LoadDatabases() error

LoadDatabases loads all configured MMDB databases

func (*Lookup) Lookup

func (l *Lookup) Lookup(ipStr string) *Result

Lookup looks up an IP address

func (*Lookup) UpdateDatabases

func (l *Lookup) UpdateDatabases() error

UpdateDatabases updates all databases

type Result

type Result struct {
	IP          string  `json:"ip"`
	CountryCode string  `json:"country_code"`
	CountryName string  `json:"country_name"`
	Continent   string  `json:"continent"`
	City        string  `json:"city,omitempty"`
	Region      string  `json:"region,omitempty"`
	PostalCode  string  `json:"postal_code,omitempty"`
	Latitude    float64 `json:"latitude,omitempty"`
	Longitude   float64 `json:"longitude,omitempty"`
	Timezone    string  `json:"timezone,omitempty"`
	ASN         uint    `json:"asn,omitempty"`
	ASNOrg      string  `json:"asn_org,omitempty"`
	// WHOIS registrant data (per AI.md PART 20)
	RegistrantOrg string `json:"registrant_org,omitempty"`
	RegistrantNet string `json:"registrant_net,omitempty"`
	Found         bool   `json:"found"`
}

Result represents a GeoIP lookup result

Jump to

Keyboard shortcuts

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