Documentation
¶
Overview ¶
Package guard holds the request guards that need no HTTP: a bounded keyed rate limiter and the client-IP rule.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientIP ¶
ClientIP takes the address from r.RemoteAddr and, when it is inside one of trusted, walks X-Forwarded-For from the right and returns the first entry that is not a trusted proxy. With no trusted proxies the header is ignored, so a sender cannot pick its own bucket.
It returns the zero Addr when RemoteAddr does not parse; callers treat that as one shared bucket.
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter is a keyed token bucket that admits count events per window. The key map is bounded at maxKeys and idle entries are evicted, so a flood of distinct keys (IPs, emails) cannot grow memory without limit.
func NewLimiter ¶
func NewLimiter(count int, window time.Duration, maxKeys int, idle time.Duration, now func() time.Time) *Limiter
NewLimiter returns a Limiter for count events per window, count >= 1. A nil now means time.Now.