geoip

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package geoip finds the country and city of a reader's address in an operator-supplied MaxMind DB file (GeoLite2-City/Country, DB-IP Lite City/Country; config geoip.database). ReputeCast never downloads the file: the operator puts it in place, keeps it updated and restarts.

Only the derived country code and English city name leave this package; the address itself is never stored for this (internal/tracking).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

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

DB is a GeoIP database held in memory. The nil DB and a DB that is still loading (or failed to) are off: Lookup finds nothing.

func Load

func Load(path string, log *slog.Logger) *DB

Load returns at once and opens the file in the background, so a large or corrupt file neither delays start-up nor serves bad data: lookups find nothing until it is verified, and a file that can't be used is logged and stays off. An empty path is off (nil).

func Open

func Open(path string) (*DB, error)

Open reads the file into memory and verifies it. Reading it whole, not memory-mapping it, means replacing the file on disk can't crash a running reader; verifying it means a corrupt or hostile file is refused before any lookup.

func (*DB) Describe

func (d *DB) Describe() string

Describe is the database's type and build date ("GeoLite2-City, built 2026-11-04"), or "" when it is off or still loading.

func (*DB) Loaded

func (d *DB) Loaded() bool

Loaded reports whether lookups can find places.

func (*DB) Lookup

func (d *DB) Lookup(ip netip.Addr) (country, city string)

Lookup returns the ISO country code (upper case) and the English city name of an address; empty when the database is off or still loading, for private, loopback and unspecified addresses, and for addresses it doesn't know. A Country database finds no city.

Jump to

Keyboard shortcuts

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