Documentation
¶
Index ¶
- Constants
- func GenerateID() string
- func GetClientIP(r *http.Request, trustCloudflare bool) string
- func GetCountry(r *http.Request) string
- func GetID(r *http.Request) string
- func ParseTrustCloudflare(val string) bool
- func ParseTrustCloudflareStrict(val string) bool
- func RegisterCountryResolver(r CountryResolver)
- func TrustCloudflareFromEnv() bool
- func WithCountry(ctx context.Context, country string) context.Context
- func WithID(ctx context.Context, id string) context.Context
- type CountryResolver
Constants ¶
const ( // HeaderCloudflareConnectingIP is set by Cloudflare to the connecting client IP. HeaderCloudflareConnectingIP = "CF-Connecting-IP" // HeaderXForwardedFor is the standard proxy header for client IP chain. HeaderXForwardedFor = "X-Forwarded-For" // EnvTrustCloudflareHeaders controls global default for trusting CF-Connecting-IP. EnvTrustCloudflareHeaders = "GATEON_TRUST_CLOUDFLARE_HEADERS" // EnvTrustedProxies is a comma-separated list of CIDRs that are trusted to provide X-Forwarded-For or CF-Connecting-IP. EnvTrustedProxies = "GATEON_TRUSTED_PROXIES" )
Variables ¶
This section is empty.
Functions ¶
func GenerateID ¶ added in v0.1.2
func GenerateID() string
GenerateID creates a new unique request ID.
func GetClientIP ¶
GetClientIP returns the client IP from the request, using CF-Connecting-IP when trustCloudflare is true (e.g. when Gateon is behind Cloudflare), otherwise X-Forwarded-For (leftmost), falling back to RemoteAddr.
func GetCountry ¶ added in v0.6.0
GetCountry returns the client country from the request context, or from CF-IPCountry header if present (and trusted), or "XX" (Unknown).
func ParseTrustCloudflare ¶
ParseTrustCloudflare parses a config value for trust_cloudflare_headers. If empty, falls back to TrustCloudflareFromEnv().
func ParseTrustCloudflareStrict ¶
ParseTrustCloudflareStrict parses trust_cloudflare_headers without env fallback. Returns false when empty or invalid.
func RegisterCountryResolver ¶ added in v0.6.9
func RegisterCountryResolver(r CountryResolver)
RegisterCountryResolver registers a global resolver for IP to Country mapping.
func TrustCloudflareFromEnv ¶
func TrustCloudflareFromEnv() bool
TrustCloudflareFromEnv returns true if GATEON_TRUST_CLOUDFLARE_HEADERS is set to a truthy value (true, 1, yes). Used as default when middleware config omits trust_cloudflare_headers.
func WithCountry ¶ added in v0.6.0
WithCountry adds a client country to the context.
Types ¶
type CountryResolver ¶ added in v0.6.9
CountryResolver is an interface for resolving IPs to country codes.