geoip

package
v0.18.21 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package geoip provides MaxMind GeoIP2/GeoLite2 database lookups for IP geolocation and ASN enrichment.

Index

Constants

This section is empty.

Variables

View Source
var DefaultReader = &Reader{}

DefaultReader is the process-wide GeoIP reader. Scalar functions reference this instance; it starts empty and is populated by Load().

Functions

func Close

func Close() error

Close releases all loaded MMDB databases.

func Load

func Load(cityPath, asnPath string) error

Load opens MaxMind MMDB database files. Either path may be empty to skip that database. Returns an error if a non-empty path fails to open.

Types

type ASNRecord

type ASNRecord struct {
	Number       uint   `maxminddb:"autonomous_system_number"`
	Organization string `maxminddb:"autonomous_system_organization"`
}

ASNRecord mirrors the MaxMind GeoIP2 ASN database schema.

type CityRecord

type CityRecord struct {
	Country struct {
		ISOCode string            `maxminddb:"iso_code"`
		Names   map[string]string `maxminddb:"names"`
	} `maxminddb:"country"`
	City struct {
		Names map[string]string `maxminddb:"names"`
	} `maxminddb:"city"`
	Subdivisions []struct {
		ISOCode string            `maxminddb:"iso_code"`
		Names   map[string]string `maxminddb:"names"`
	} `maxminddb:"subdivisions"`
	Postal struct {
		Code string `maxminddb:"code"`
	} `maxminddb:"postal"`
	Location struct {
		Latitude  float64 `maxminddb:"latitude"`
		Longitude float64 `maxminddb:"longitude"`
		TimeZone  string  `maxminddb:"time_zone"`
	} `maxminddb:"location"`
	Continent struct {
		Code  string            `maxminddb:"code"`
		Names map[string]string `maxminddb:"names"`
	} `maxminddb:"continent"`
}

CityRecord mirrors the MaxMind GeoIP2 City database schema.

type Reader

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

Reader wraps MaxMind MMDB database handles with thread-safe access.

func (*Reader) HasASN

func (r *Reader) HasASN() bool

HasASN reports whether an ASN database is loaded.

func (*Reader) HasCity

func (r *Reader) HasCity() bool

HasCity reports whether a city database is loaded.

func (*Reader) LookupASN

func (r *Reader) LookupASN(ip net.IP) *ASNRecord

LookupASN queries the ASN database for the given IP. Returns nil if no ASN database is loaded or the IP is not found.

func (*Reader) LookupCity

func (r *Reader) LookupCity(ip net.IP) *CityRecord

LookupCity queries the city database for the given IP. Returns nil if no city database is loaded or the IP is not found.

Jump to

Keyboard shortcuts

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