remoteip

package
v1.31.3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIPSpoofAttack = errors.New("ip spoofing attack detected")
)
View Source
var (
	ErrNoPeerInfo = errors.New("no peer information in context")
)

Functions

This section is empty.

Types

type GRPCRemoteIPParser added in v1.31.3

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

GRPCRemoteIPParser extracts and validates the client's true IP address from gRPC metadata. This is adapted from the HTTP RemoteIPParser to work with gRPC contexts and metadata.

func NewGRPCRemoteIPParser added in v1.31.3

func NewGRPCRemoteIPParser(trustedProxies []string) *GRPCRemoteIPParser

NewGRPCRemoteIPParser creates a new GRPCRemoteIPParser with the list of trusted proxies. If the list is empty, it will use the default trusted proxies.

func (*GRPCRemoteIPParser) GetIP added in v1.31.3

func (p *GRPCRemoteIPParser) GetIP(ctx context.Context) (string, error)

GetIP extracts the client's true IP address from the gRPC context following a similar approach to the HTTP version's calculate_ip method.

type HTTPRemoteIPParser added in v1.31.3

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

HTTPRemoteIPParser extracts and validates the client's true IP address from HTTP request headers. This is a port of the Rails code: https://github.com/rails/rails/blob/v8.0.2/actionpack/lib/action_dispatch/middleware/remote_ip.rb#L109-L167

func NewHTTPRemoteIPParser added in v1.31.3

func NewHTTPRemoteIPParser(trustedProxies []string) *HTTPRemoteIPParser

NewRemoteIPParser creates a new RemoteIPParser with the list of trusted proxies. If the list is empty, it will use the default trusted proxies.

func (*HTTPRemoteIPParser) GetIP added in v1.31.3

func (p *HTTPRemoteIPParser) GetIP(r *http.Request) (string, error)

GetIP extracts the client's true IP address from the request following a similar approach to Rails' calculate_ip method.

type RemoteIPParser deprecated

type RemoteIPParser struct {
	HTTPRemoteIPParser
}

RemoteIPParser extracts and validates the client's true IP address from HTTP request headers.

Deprecated: This struct added to maintain backwards compatibility and will be removed later. Use HTTPRemoteIPParser instead.

func NewRemoteIPParser deprecated

func NewRemoteIPParser(trustedProxies []string) *RemoteIPParser

NewRemoteIPParser creates a new RemoteIPParser with the list of trusted proxies. If the list is empty, it will use the default trusted proxies.

Deprecated: This method added to maintain backwards compatibility and will be removed later. Use HTTPRemoteIPParser instead.

Jump to

Keyboard shortcuts

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