util

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHostAndPortFromRemoteAddr added in v0.0.19

func GetHostAndPortFromRemoteAddr(remoteAddr string) (string, int)

func GetHostAndPortFromRequest added in v0.0.19

func GetHostAndPortFromRequest(req *http.Request) (string, int)

func GetRemoteAddrFromRequest added in v0.0.19

func GetRemoteAddrFromRequest(req *http.Request) string

func IPInAny added in v0.1.2

func IPInAny(host string, nets []*net.IPNet) bool

IPInAny reports whether host (a bare IP, no port) falls within any of the given networks. A non-IP host or an empty network list returns false.

func IsPrivateOrLoopback added in v0.0.24

func IsPrivateOrLoopback(host string) bool

IsPrivateOrLoopback reports whether host is a loopback, RFC1918 private, or link-local IP address. host should be a bare IP (no port); non-IP hostnames return false. Used to exempt trusted/local sources (operators testing, internal SSRF callbacks) from volume-based bot detection.

func ParseCIDRs added in v0.1.2

func ParseCIDRs(spec string) ([]*net.IPNet, error)

ParseCIDRs parses a comma-separated list of CIDRs and bare IPs into networks. A bare IP (e.g. "1.2.3.4" or "2001:db8::1") is treated as a single-host network (/32 or /128). Empty entries and surrounding whitespace are ignored; an empty spec yields a nil slice and no error. The first unparseable entry returns an error so config mistakes surface loudly rather than silently matching nothing.

func RequestIPChain added in v0.0.24

func RequestIPChain(req *http.Request) []string

RequestIPChain returns the unique, order-preserving chain of source IPs for an HTTP request: X-Forwarded-For entries (client first), then X-Real-Ip, then the direct TCP peer. Duplicates are collapsed. Forwarded headers are client-controlled and can be spoofed, so treat the chain as informational rather than authoritative.

Types

This section is empty.

Jump to

Keyboard shortcuts

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