Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetClientIP ¶
GetClientIP get clientIP from context. If not found, return empty string
Warning: Request context should be setup before using this function
func GetRequestId ¶
GetRequestId get requestId from context. If not found, return empty string
Warning: Request context should be setup before using this function
Types ¶
type Option ¶
func WithClientIP ¶
func WithClientIP(config WithClientIPConfig) Option
WithClientIP setup client IP context with XFF Spoofing prevention support.
If request is from proxies, it will use first IP from `X-Forwarded-For` header by default.
func WithRequestId ¶
func WithRequestId() Option
type WithClientIPConfig ¶
type WithClientIPConfig struct { // [Optional] TrustedProxiesIP is a list of all proxies IP ranges that's between the server and the client. // // If it's provided, it will walk backwards from the last IP in `X-Forwarded-For` header // and use first IP that's not trusted proxy(not in the given IP ranges.) // // **If you want to use this option, you should provide all of probable proxies IP ranges.** // // This is lowest priority. TrustedProxiesIP []string `env:"TRUSTED_PROXIES_IP" mapstructure:"trusted_proxies_ip"` // [Optional] TrustedHeader is a header name for getting client IP. (e.g. X-Real-IP, CF-Connecting-IP, etc.) // // This is highest priority, it will ignore rest of the options if it's provided. TrustedHeader string `env:"TRUSTED_HEADER" mapstructure:"trusted_proxies_header"` // EnableRejectMalformedRequest return 403 Forbidden if the request is from proxies, but can't extract client IP EnableRejectMalformedRequest bool `env:"ENABLE_REJECT_MALFORMED_REQUEST" envDefault:"false" mapstructure:"enable_reject_malformed_request"` }
Click to show internal directories.
Click to hide internal directories.