geoip

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package geoip resolves a client IP address to a best-guess ISO country code, for DetectedCountry only (display/discovery convenience — never authoritative for billing; see the localization module's middleware).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudflareHeaderResolver

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

CloudflareHeaderResolver trusts a header injected by Cloudflare's edge (or a compatible upstream proxy) instead of doing its own IP lookup. Only correct to use when the app's traffic genuinely all passes through Cloudflare (or something else that sets and can be trusted to set this header) — otherwise a client can spoof it.

func NewCloudflareHeaderResolver

func NewCloudflareHeaderResolver(headerName string) *CloudflareHeaderResolver

func (*CloudflareHeaderResolver) HeaderName

func (r *CloudflareHeaderResolver) HeaderName() string

HeaderName is the header this resolver reads — callers extract it from the incoming request and pass the value to Lookup as ip (despite the parameter name, this resolver ignores the actual IP and only cares about the pre-resolved header value the caller hands it).

func (*CloudflareHeaderResolver) Lookup

func (r *CloudflareHeaderResolver) Lookup(_ context.Context, headerValue string) (string, bool)

type MaxMindResolver

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

MaxMindResolver looks up countries from a self-hosted GeoLite2-Country (or commercial GeoIP2-Country) .mmdb file — no per-request external API call.

func NewMaxMindResolver

func NewMaxMindResolver(path string) (*MaxMindResolver, error)

NewMaxMindResolver opens the .mmdb file at path. The returned resolver owns the file handle; call Close when the host app shuts down.

func (*MaxMindResolver) Close

func (r *MaxMindResolver) Close() error

func (*MaxMindResolver) Lookup

func (r *MaxMindResolver) Lookup(_ context.Context, ip string) (string, bool)

type NoneResolver

type NoneResolver struct{}

NoneResolver never resolves anything — used when GeoIP detection is disabled (Config.GeoIP.Provider == "none").

func (NoneResolver) Lookup

func (NoneResolver) Lookup(_ context.Context, _ string) (string, bool)

type Resolver

type Resolver interface {
	Lookup(ctx context.Context, ip string) (countryCode string, ok bool)
}

Resolver looks up the country an IP address most likely belongs to. ok=false means "no confident answer" (private/unroutable IP, provider disabled, lookup failure, or the DB has no entry) — callers should fall back to the module's configured default rather than treating it as an error.

Jump to

Keyboard shortcuts

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