Documentation
¶
Index ¶
Constants ¶
View Source
const ( // DefaultRate is the number of allowed requests per window DefaultRate = 5 // DefaultWindow is the rate limiting window duration DefaultWindow = 1 * time.Minute // CleanupInterval is the cleanup frequency for old entries CleanupInterval = 5 * time.Minute )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IPRateLimiter ¶
type IPRateLimiter struct {
// contains filtered or unexported fields
}
IPRateLimiter manages rate limiting per IP
func NewDefaultIPRateLimiter ¶
func NewDefaultIPRateLimiter() *IPRateLimiter
NewDefaultIPRateLimiter creates a rate limiter with default values
func NewIPRateLimiter ¶
func NewIPRateLimiter(rate int, window time.Duration) *IPRateLimiter
NewIPRateLimiter creates a new rate limiter
func (*IPRateLimiter) Allow ¶
func (rl *IPRateLimiter) Allow(ip string) bool
Allow checks if a request is allowed for a given IP
func (*IPRateLimiter) GetStats ¶
func (rl *IPRateLimiter) GetStats() Stats
func (*IPRateLimiter) Middleware ¶
func (rl *IPRateLimiter) Middleware(next http.HandlerFunc) http.HandlerFunc
Middleware creates an HTTP middleware for rate limiting
func (*IPRateLimiter) Reset ¶
func (rl *IPRateLimiter) Reset(ip string)
Reset resets the counter for an IP
Click to show internal directories.
Click to hide internal directories.