Documentation
¶
Index ¶
- Constants
- func HTTPIPFilterMiddleware(filter *IPFilter) func(http.Handler) http.Handler
- func HTTPRateLimitMiddleware(limiter *IPRateLimiter) func(http.Handler) http.Handler
- func WebSocketRateLimitHandler(limiter *IPRateLimiter, handler func(*melody.Session, []byte)) func(*melody.Session, []byte)
- type IPFilter
- type IPRateLimiter
Constants ¶
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 HTTPIPFilterMiddleware ¶ added in v2.7.0
HTTPIPFilterMiddleware creates an HTTP middleware that filters requests by IP. This middleware applies to both regular HTTP requests and WebSocket upgrade requests.
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 IPFilter ¶ added in v2.7.0
type IPFilter struct {
// contains filtered or unexported fields
}
IPFilter manages IP allowlist filtering for both HTTP and WebSocket connections
func NewIPFilter ¶ added in v2.7.0
NewIPFilter creates a new IP filter from a list of allowed IPs/CIDRs. Empty list means all IPs are allowed (no filtering).
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.