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) 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.