ip

package
v1.4.2-mod Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package ip implements utility routines to manipulate IP and CIDR. It allows searching an IP on a list, and find if an IP is part of a list of CIDR.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRemoteIP

func GetRemoteIP(req *http.Request, strategy *PoolStrategy, customHeader string) (string, error)

GetRemoteIP It returns the first IP that is not in the pool, or the empty string otherwise.

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(log *logger.Log, 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.

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.

Jump to

Keyboard shortcuts

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