geolocation

package
v0.67.3 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package geolocation provides IP-to-country lookups using MaxMind GeoLite2 databases.

Index

Constants

View Source
const (
	// EnvDisable disables geolocation lookups entirely when set to a truthy value.
	EnvDisable = "NB_PROXY_DISABLE_GEOLOCATION"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Lookup

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

Lookup provides IP geolocation lookups.

func NewLookup

func NewLookup(logger *log.Logger, dataDir string) (*Lookup, error)

NewLookup opens or downloads the GeoLite2-City MMDB in dataDir. Returns nil without error if geolocation is disabled via environment variable, no data directory is configured, or the download fails (graceful degradation: country restrictions will deny all requests).

func (*Lookup) Available

func (l *Lookup) Available() bool

Available reports whether the lookup has a loaded database.

func (*Lookup) Close

func (l *Lookup) Close() error

Close releases the database resources.

func (*Lookup) LookupAddr

func (l *Lookup) LookupAddr(addr netip.Addr) Result

LookupAddr returns the country ISO code and city name for the given IP. Returns an empty Result if the database is nil or the lookup fails.

type Result

type Result struct {
	CountryCode     string
	CityName        string
	SubdivisionCode string
	SubdivisionName string
}

Result holds the outcome of a geo lookup.

Jump to

Keyboard shortcuts

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