geoip

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package geoip resolves a client address to a country code.

It resolves a country and nothing else, which is a privacy decision rather than an unfinished one. The same database carries region and city, and both are dramatically more identifying than a country — city plus timestamp is close to a location history. There is nowhere in the product that shows them, so storing them would be collecting personal data for no purpose, which is exactly what the rest of the analytics design goes out of its way not to do. The columns exist and stay null; adding them is a Phase 2 decision that would need a UI and a reason.

The database itself is never redistributed in the image: MaxMind's licence does not allow it, so geographic reporting is off unless an operator supplies a file. That is why every method tolerates a nil Resolver — "no database" is the default state, not an error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resolver

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

Resolver looks up countries in a MaxMind DB file.

Lookups are safe to call concurrently, which is what lets the ingester share one Resolver across a batch without copying or locking.

func Open

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

Open loads a MaxMind DB file. An empty path returns a nil Resolver, which is valid and resolves nothing.

The file is validated by opening it rather than by trusting the path: a truncated or wrong-format database fails here, at startup, instead of returning empty countries for the life of the process.

func (*Resolver) Close

func (r *Resolver) Close() error

Close releases the mapped file.

func (*Resolver) Country

func (r *Resolver) Country(addr netip.Addr) string

Country returns the ISO 3166-1 alpha-2 code for an address, or "" when it is unknown.

Every failure — no database, unroutable address, address absent from the database, a record without a country — is the same empty answer. A caller has nothing different to do about them, and an error return would put a branch on the path that enriches every click.

func (*Resolver) Description

func (r *Resolver) Description() string

Description returns the database's own type and build date, for the startup log. An operator who mounted the wrong file should be able to see that from the log rather than from empty charts.

func (*Resolver) Enabled

func (r *Resolver) Enabled() bool

Enabled reports whether a database is loaded.

Jump to

Keyboard shortcuts

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