middleware

package
v2.6.0-beta10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 11, 2025 License: GPL-3.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL