ip

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: May 29, 2025 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetHTTPClientIP

func GetHTTPClientIP(r *http.Request, options GetHTTPClientIPOptions) string

GetHTTPClientIP will extract ip from headers or just remoteaddr

code mainly from dts gateway code

ref, https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-For todo, add support for Forwarded , https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Forwarded

func IsPrivateIP

func IsPrivateIP(ip net.IP) bool

IsPrivateIP returns true if the given IP is in private ip mask range

func IsPublicIP

func IsPublicIP(ip net.IP) bool

IsPublicIP returns true if the given IP is not in private ip mask range

Types

type FilterStrategy

type FilterStrategy uint8
const (
	FirstIP FilterStrategy = iota
	LastPublicIP
)

type GetHTTPClientIPOptions

type GetHTTPClientIPOptions struct {
	FilterStrategy       FilterStrategy
	SupportHeaderXRealIP bool // X-Real-IP is used by nginx ngx_http_realip_module
}

Jump to

Keyboard shortcuts

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