ip

package
v0.0.0-...-d8b0a59 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 7 Imported by: 1 module, 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

This section is empty.

Types

type Checker

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

Checker allows to check that addresses are in a trusted IPS

func NewChecker

func NewChecker(trustedIPs []string) (*Checker, error)

NewChecker builds a new Checker given a list of CIDR-Strings to trusted IPs.

func (*Checker) Contains

func (ip *Checker) Contains(addr string) (bool, error)

func (*Checker) ContainsIP

func (ip *Checker) ContainsIP(addr net.IP) bool

func (*Checker) IsAuthorized

func (ip *Checker) IsAuthorized(addr string) error

IsAuthorized checks if provided request is authorized by the trusted IPs.

type DepthStrategy

type DepthStrategy struct {
	Depth int
	// IPv6Subnet instructs the strategy to return the first IP of the subnet where IP belongs.
	IPv6Subnet *int
}

DepthStrategy a strategy based on the depth inside the X-Forwarded-For from right to left.

func (*DepthStrategy) GetIP

func (s *DepthStrategy) GetIP(req *http.Request) string

GetIP returns the selected IP.

type PoolStrategy

type PoolStrategy struct {
	Checker *Checker
}

PoolStrategy is a strategy based on an IP Checker. It allows to check whether addresses are in a given pool of IPs.

func (*PoolStrategy) GetIP

func (s *PoolStrategy) GetIP(req *http.Request) string

GetIP checks the list of Forwarded IPs (most recent first) against the Checker pool of IPs. It returns the first IP that is not in the pool, or the empty string otherwise.

type RemoteAddrStrategy

type RemoteAddrStrategy struct {
	// IPv6Subnet instructs the strategy to return the first IP of the subnet where IP belongs.
	IPv6Subnet *int
}

RemoteAddrStrategy a strategy that always return the remote address.

func (*RemoteAddrStrategy) GetIP

func (s *RemoteAddrStrategy) GetIP(req *http.Request) string

GetIP returns the selected IP.

type Strategy

type Strategy interface {
	GetIP(req *http.Request) string
}

Strategy a strategy for IP selection.

Jump to

Keyboard shortcuts

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