geolocation

package
v0.83.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: BSD-3-Clause, AGPL-3.0 Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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