{"modulePath":"github.com/gomodedev/gomode","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package geoip\n\nPackage geoip provides IP origin and country allowlist enforcement.\n\n## Types\n\n```go\ntype Checker struct {\n\t// contains filtered or unexported fields\n}\n```\nChecker resolves IP addresses to country codes or named origins using a MaxMind MMDB file and optional named CIDR groups, and enforces an allowlist.\n\n```go\nfunc NewChecker(ctx context.Context, log *slog.Logger, allowlistStr, dbPath, cacheDir string) (*Checker, error)\n```\nNewChecker builds a Checker from a comma-separated allowlist string and an optional geo DB path. Named origins that require network fetches are resolved automatically. Country codes must occur in the database; their presence is checked at startup before fetching named origins. Results are cached under cacheDir for 24 hours; stale cache entries are used when refresh fails. Fetch failures are logged as warnings and do not abort startup.\n\n```go\nfunc Open(dbPath string) (*Checker, error)\n```\nOpen opens an MMDB file for enrichment without filtering. It classifies loopback, private, unspecified and link-local addresses as local, and 100.64.0.0/10 as tailscale; all other addresses use their MMDB country code.\n\n```go\nfunc (c *Checker) CheckOrigin(clientIP string) (string, bool)\n```\nCheckOrigin resolves the IP origin and reports whether it is allowlisted.\n\nIt returns the resolved origin even when the allowlist blocks the IP, so callers can use the same lookup result for logging and error messages. It returns \"\", false for invalid IPs unless no allowlist is configured.\n\n```go\nfunc (c *Checker) Close() error\n```\nClose releases MMDB reader resources.\n\n```go\ntype Config struct {\n\tDB           string\n\tAllowOrigins []string\n}\n```\nConfig selects optional country enrichment and origin filtering. Immutable after startup. Hosts own database path expansion and the cache directory path.\n\n```go\nfunc (c *Config) Open(ctx context.Context, log *slog.Logger, cacheDir string) (*Checker, error)\n```\nOpen validates the configuration and opens the optional checker. With neither setting it returns nil, nil. DB alone enriches without filtering or network fetches. Origin filtering uses the named-network cache in cacheDir; Open creates that directory only when a registered source needs caching. Empty cacheDir selects uncached resolution. The caller owns the returned checker.\n\n```go\nfunc (c *Config) Validate() error\n```\nValidate checks origin tokens and requires geo\\_db when filtering by country. Origin tokens are CIDRs, two-letter country tokens (case-insensitive), or registered named origins. Open checks country tokens against the database. An empty list disables filtering; empty DB skips country enrichment. Validation performs no filesystem or network operations.\n\n","path":"github.com/gomodedev/gomode/httpserver/geoip","name":"geoip","synopsis":"Package geoip provides IP origin and country allowlist enforcement.","isRedistributable":true}
