limiter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 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 IPRateLimiter

type IPRateLimiter struct {
	Limiters map[string]*RateLimiter
	Mutex    sync.Mutex
}

Maps IP addresses to their respective rate limiters

func NewIPRateLimiter

func NewIPRateLimiter() *IPRateLimiter

func (*IPRateLimiter) GetLimiter

func (i *IPRateLimiter) GetLimiter(ip string, limit, refresh float64) *RateLimiter

Gets limiter for IP address from struct map

type RateLimiter

type RateLimiter struct {
	Tokens         float64   // Current number of tokens
	MaxTokens      float64   // Max number of tokens
	RefillRate     float64   // Tokens added per second
	LastRefillTime time.Time // Last time tokens were refilled
	Mutex          sync.Mutex
}

func NewRateLimiter

func NewRateLimiter(maxTokens, refillRate float64) *RateLimiter

Creates new instance of a RateLimiter

func (*RateLimiter) Allow

func (r *RateLimiter) Allow() bool

Determines whether a request will be allowed or rejected

func (*RateLimiter) RefillTokens

func (r *RateLimiter) RefillTokens()

Refill available tokens in limiter struct

Jump to

Keyboard shortcuts

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