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
Click to show internal directories.
Click to hide internal directories.