clientip

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package clientip resolves client addresses behind configurable proxies.

Index

Constants

This section is empty.

Variables

View Source
var DefaultHeaders = []string{"CF-Connecting-IP", "True-Client-IP", "Ali-CDN-Real-IP", "X-Forwarded-For", "X-Real-IP", "Client-IP", "X-Cluster-Client-IP", "Forwarded-For", "X-Forwarded", "Forwarded"}

Functions

func Register

func Register(engine *gin.Engine)

Register installs the resolver before the framework's HTTP middleware.

Types

type Config

type Config struct {
	Mode           string
	Headers        []string
	TrustedProxies []string
	Cloudflare     bool
	CloudFront     bool
	Directory      string
}

Config controls client address resolution and optional CDN range updates.

type Resolver

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

Resolver maintains immutable snapshots for concurrent requests.

func New

func New(cfg Config) (*Resolver, error)

func Resolve

func Resolve() *Resolver

Resolve returns the application-managed resolver.

func (*Resolver) Close

func (r *Resolver) Close() error

func (*Resolver) IP

func (r *Resolver) IP(req *http.Request) string

IP resolves a request using the configured mode.

func (*Resolver) Status

func (r *Resolver) Status() map[string]Status

func (*Resolver) Update

func (r *Resolver) Update(ctx context.Context)

Update fetches enabled providers, retaining the previous snapshot on failure.

type Status

type Status struct {
	UpdatedAt time.Time `json:"updated_at"`
	Error     string    `json:"error,omitempty"`
	Count     int       `json:"count"`
}

Jump to

Keyboard shortcuts

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