Documentation
¶
Overview ¶
Package middleware provides HTTP middleware for the REST API
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RateLimitMiddleware ¶
func RateLimitMiddleware(limiter *RateLimiter) func(http.Handler) http.Handler
RateLimitMiddleware creates HTTP middleware for rate limiting
Types ¶
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter provides token bucket rate limiting
func DefaultAPIRateLimiter ¶
func DefaultAPIRateLimiter() *RateLimiter
DefaultAPIRateLimiter returns a rate limiter for general API endpoints
func DefaultLoginRateLimiter ¶
func DefaultLoginRateLimiter() *RateLimiter
DefaultLoginRateLimiter returns a rate limiter for login endpoints
func NewRateLimiter ¶
func NewRateLimiter(maxTokens int, refillRate time.Duration) *RateLimiter
NewRateLimiter creates a new rate limiter
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(ip string) bool
Allow checks if a request from the given IP is allowed
func (*RateLimiter) Cleanup ¶
func (rl *RateLimiter) Cleanup(maxAge time.Duration)
Cleanup removes stale entries older than the given duration
func (*RateLimiter) StartAutoCleanup ¶
func (rl *RateLimiter) StartAutoCleanup(interval time.Duration, maxAge time.Duration)
StartAutoCleanup starts a background goroutine that periodically cleans up stale entries
Click to show internal directories.
Click to hide internal directories.