ratelimit

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeyRateLimiter

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

APIKeyRateLimiter manages rate limits per API key

func NewAPIKeyRateLimiter

func NewAPIKeyRateLimiter() *APIKeyRateLimiter

NewAPIKeyRateLimiter creates a new API key-based rate limiter

func (*APIKeyRateLimiter) Allow

func (rl *APIKeyRateLimiter) Allow(apiKey string) (bool, error)

Allow checks if a request with an API key is allowed

func (*APIKeyRateLimiter) SetLimit

func (rl *APIKeyRateLimiter) SetLimit(apiKey string, config RateLimitConfig)

SetLimit sets the rate limit for an API key

type IPRateLimiter

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

IPRateLimiter manages rate limits per IP address

func NewIPRateLimiter

func NewIPRateLimiter(maxTokens, refillRate float64) *IPRateLimiter

NewIPRateLimiter creates a new IP-based rate limiter

func (*IPRateLimiter) Allow

func (rl *IPRateLimiter) Allow(ip string) bool

Allow checks if a request from an IP is allowed

type RateLimitConfig

type RateLimitConfig struct {
	MaxTokens  float64
	RefillRate float64
	BurstSize  int
}

RateLimitConfig defines rate limit configuration

type RateLimiter

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

RateLimiter implements a token bucket rate limiter

func NewRateLimiter

func NewRateLimiter(maxTokens float64, refillRate float64) *RateLimiter

NewRateLimiter creates a new rate limiter

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow() bool

Allow checks if a request is allowed

func (*RateLimiter) AllowN

func (rl *RateLimiter) AllowN(n float64) bool

AllowN checks if n requests are allowed

func (*RateLimiter) Wait

func (rl *RateLimiter) Wait(ctx context.Context) error

Wait blocks until a token is available

Jump to

Keyboard shortcuts

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