Documentation
¶
Index ¶
Constants ¶
View Source
const ( RequestsPerMinute = 100 // Simple limit - 100 requests per minute per IP BurstSize = 20 // Allow burst of 20 requests )
Variables ¶
This section is empty.
Functions ¶
func HTTPRateLimitMiddleware ¶
func HTTPRateLimitMiddleware(limiter *IPRateLimiter) func(http.Handler) http.Handler
HTTPRateLimitMiddleware creates an HTTP rate limiting middleware
func WebSocketRateLimitHandler ¶
func WebSocketRateLimitHandler( limiter *IPRateLimiter, handler func(*melody.Session, []byte), ) func(*melody.Session, []byte)
WebSocketRateLimitHandler wraps a WebSocket message handler with rate limiting
Types ¶
type IPRateLimiter ¶
type IPRateLimiter struct {
// contains filtered or unexported fields
}
IPRateLimiter manages rate limiters per IP address for both HTTP and WebSocket
func NewIPRateLimiter ¶
func NewIPRateLimiter() *IPRateLimiter
NewIPRateLimiter creates a new IP-based rate limiter with hardcoded limits
func (*IPRateLimiter) Cleanup ¶
func (rl *IPRateLimiter) Cleanup()
Cleanup removes old entries that haven't been seen recently
func (*IPRateLimiter) GetLimiter ¶
func (rl *IPRateLimiter) GetLimiter(ip string) *rate.Limiter
GetLimiter returns the rate limiter for the given IP
func (*IPRateLimiter) StartCleanup ¶
func (rl *IPRateLimiter) StartCleanup(ctx context.Context)
StartCleanup starts a goroutine to periodically clean up old rate limiters. The cleanup goroutine will stop when the provided context is cancelled.
Click to show internal directories.
Click to hide internal directories.