geo

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package geo resolves a client IP into country/city (optional, via a MaxMind GeoLite2 mmdb) and parses a User-Agent into device/browser/os.

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 geographic info; nil-safe when no database is configured.

func Open

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

Open loads the mmdb at path. An empty path yields a no-op resolver.

The file is read into memory rather than memory-mapped: geoip2.Open uses mmap, which fails with ENODEV ("no such device") on filesystems that don't support it (some Docker bind mounts / overlay / network volumes). Reading the bytes avoids that and works everywhere.

func (*Resolver) Close

func (r *Resolver) Close()

func (*Resolver) Locate

func (r *Resolver) Locate(ip string) (country, region, city string)

Country, Region, and City for the given IP; empty strings when unavailable.

type UAInfo

type UAInfo struct {
	Device  string
	Browser string
	OS      string
}

UAInfo is the parsed device/browser/os breakdown.

func ParseUA

func ParseUA(ua string) UAInfo

ParseUA classifies a User-Agent string.

Jump to

Keyboard shortcuts

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