ratelimit

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter implements an in-memory rate limiter using sliding window algorithm

func NewRateLimiter

func NewRateLimiter() *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(key string, limit int, windowDuration time.Duration) bool

Allow checks if a request is allowed based on the rate limit Returns true if the request is allowed, false if rate limit exceeded

func (*RateLimiter) GetCount

func (rl *RateLimiter) GetCount(key string, windowDuration time.Duration) int

GetCount returns the current count for a key within the window

func (*RateLimiter) Reset

func (rl *RateLimiter) Reset(key string)

Reset removes all tracking data for a specific key

Jump to

Keyboard shortcuts

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