ip

package
v2.5.0-rc5 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 5 Imported by: 1

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)

Contains checks if provided address is in the trusted IPs.

func (*Checker) ContainsIP

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

ContainsIP checks if provided address is in the trusted IPs.

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
}

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 return the selected IP.

type PoolStrategy added in v2.4.9

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 added in v2.4.9

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{}

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