ratelimit

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 3 Imported by: 0

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

type Stats

type Stats struct {
	TotalIPs       int
	ActiveLimiters int
}

Stats contains statistics about the rate limiter

Jump to

Keyboard shortcuts

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