Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromContext ¶
FromContext extracts the user IP address from ctx, if present.
func FromRequest ¶
FromRequest returns the client IP for r. When X-Forwarded-For is trusted and present it uses the left-most (original client) entry of the header; a multi-hop value such as "client, proxy1, proxy2" is parsed correctly rather than failing to parse. Otherwise it falls back to the connection's RemoteAddr.
func FromRequestIPv4 ¶
FromRequestIPv4 extracts the IPv4 address from the request as a string. Returns the IPv4 string if the client IP is IPv4 or IPv4-mapped IPv6, otherwise returns an empty string.
func NewContext ¶
NewContext returns a new Context carrying userIP.
func SetTrustForwardedFor ¶
func SetTrustForwardedFor(trust bool)
SetTrustForwardedFor configures whether X-Forwarded-For is trusted. Call this at startup based on deployment topology.