geo

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package geo resolves visitor IPs to a country code using the DB-IP Lite free database (db-ip.com, CC BY 4.0 — the dashboard credits it wherever countries render). Chosen over MaxMind because the download needs no account or key.

Design constraints, in order: (1) privacy — the IP is used for one in-memory lookup at ingest and never stored; only the ISO country code is stamped on the event. (2) zero dependencies — the CSV edition parses with the stdlib into a sorted range table (~600k IPv4 ranges ≈ 12MB resident), no mmdb reader needed. (3) never block serving — Open returns immediately and loads (downloading the ~10MB file on first boot) in the background; lookups before readiness return "" and events simply carry no country, exactly like a backend event would.

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
}

func Open

func Open(path string) *Resolver

Open returns a resolver immediately and loads path in the background. If the file is missing it is downloaded from DB-IP first (month-stamped URL, falling back to the previous month around release day). Any failure logs once and leaves the resolver empty — geo is an enrichment, never a dependency.

func (*Resolver) Country

func (r *Resolver) Country(ip net.IP) string

Country returns the ISO 3166-1 alpha-2 code for ip, or "" when unknown, non-IPv4, or the table isn't loaded yet.

Jump to

Keyboard shortcuts

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