Documentation
¶
Overview ¶
Package ratelimiter provides basic rate limiting functionality as a with middeware.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrRateLimitExceeded = errors.New("rate limit exceeded, please try again later")
ErrRateLimitExceeded happens when the connection was denied due to the rate limit being exceeded.
Functions ¶
func Middleware ¶
func Middleware(limiter RateLimiter) wish.Middleware
Middleware provides a new rate limiting Middleware.
Types ¶
type RateLimiter ¶
RateLimiter implementations should check if a given session is allowed to proceed or not, returning an error if they aren't. Its up to the implementation to handle what identifies an session as well as the implementation details of these limits.
func NewRateLimiter ¶
func NewRateLimiter(r rate.Limit, burst int, maxEntries int) RateLimiter
NewRateLimiter returns a new RateLimiter that allows events up to rate rate, permits bursts of at most burst tokens and keeps a cache of maxEntries limiters.
Internally, it creates a LRU Cache of *rate.Limiter, in which the key is the remote IP address.