Help us shape the future of Go! Take the 2026 Go Developer Survey

geoip

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GeoIPResolver

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

GeoIPResolver resolves IP addresses to ISO 3166-1 alpha-2 country codes using a MaxMind DB (.mmdb) file via the oschwald/maxminddb-golang library. A nil pointer or one opened with an empty path is a safe no-op — Lookup always returns "".

func New

func New(path string) (*GeoIPResolver, error)

New opens the mmdb file at path. If path is empty, returns nil (feature disabled).

func (*GeoIPResolver) Close

func (g *GeoIPResolver) Close()

Close releases the mmdb file handle.

func (*GeoIPResolver) Lookup

func (g *GeoIPResolver) Lookup(ipStr string) string

Lookup resolves an IP address string to an ISO 3166-1 alpha-2 country code. Returns "" if the resolver is nil, the IP is private/invalid, or no country is found. Results are cached for 24 hours — IPs rarely change country, and the cache avoids re-walking the mmdb binary tree for the same node on every page load.

Jump to

Keyboard shortcuts

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