clientip

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

func FromContext(ctx context.Context) net.IP

FromContext extracts the user IP address from ctx, if present.

func FromRequest

func FromRequest(r *http.Request) net.IP

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

func FromRequestIPv4(r *http.Request) string

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

func NewContext(ctx context.Context, clientIP net.IP) context.Context

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.

Types

type ClientIP

type ClientIP struct {
}

func NewClientIP

func NewClientIP(component string) *ClientIP

func (*ClientIP) Middleware

func (clientip *ClientIP) Middleware(next http.Handler) http.Handler

Jump to

Keyboard shortcuts

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