Documentation ¶
Overview ¶
Tokenbucket based request rate limiter
Index ¶
Constants ¶
View Source
const DefaultCapacity = 65536
View Source
const UndefinedDelay = -1
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConfigMapperFn ¶
ConfigMapperFn is a mapper function that is used by the `TokenLimiter` middleware to retrieve `RateSet` from HTTP requests.
type RateSet ¶
type RateSet struct {
// contains filtered or unexported fields
}
RateSet maintains a set of rates. It can contain only one rate per period at a time.
type TokenLimiter ¶
type TokenLimiter struct {
// contains filtered or unexported fields
}
TokenLimiter implements rate limiting middleware.
func NewLimiter ¶
func NewLimiter(defaultRates *RateSet, capacity int, mapper limit.MapperFn, configMapper ConfigMapperFn, clock timetools.TimeProvider) (*TokenLimiter, error)
NewLimiter constructs a `TokenLimiter` middleware instance.
func (*TokenLimiter) DefaultRates ¶
func (tl *TokenLimiter) DefaultRates() *RateSet
DefaultRates returns the default rate set of the limiter. The only reason to Provide this method is to facilitate testing.
func (*TokenLimiter) ProcessRequest ¶
func (*TokenLimiter) ProcessResponse ¶
func (tl *TokenLimiter) ProcessResponse(r request.Request, a request.Attempt)
Click to show internal directories.
Click to hide internal directories.