Documentation
¶
Overview ¶
Package ipgeo provides IP origin and country allowlist enforcement.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetClientIP ¶
GetClientIP extracts the real client IP from a request, checking X-Forwarded-For and X-Real-IP headers for proxied requests.
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker resolves IP addresses to country codes or named origins using a MaxMind MMDB file and optional named CIDR groups, and enforces an allowlist.
func NewChecker ¶ added in v0.5.4
NewChecker builds a Checker from a comma-separated allowlist string and an optional geo DB path. Named origins that require network fetches are resolved automatically. 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.
func (*Checker) CheckOrigin ¶ added in v0.10.1
CheckOrigin resolves the IP origin and reports whether it is allowlisted.
It 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.