Documentation ¶
Overview ¶
Package rate offers a rate limiter middleware
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BucketLimit ¶
BucketLimit defines how a bucket is filled
type RateLimiter ¶
type RateLimiter struct { Limits []BucketLimit Key Key // contains filtered or unexported fields }
RateLimiter allows rate limiting requests by IP
The basic algorithm is a bucket filled with tokens: - every `Delay` `Count` tokens are added into the bucket - every time a request is made it takes a token from the bucket
func New ¶
func New(key Key, size int, limits ...BucketLimit) (*RateLimiter, error)
New creates a new ratelimiter
func (*RateLimiter) Middleware ¶
func (l *RateLimiter) Middleware(next router.Route) router.Route
Middleware is a router middleware
Click to show internal directories.
Click to hide internal directories.