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 MaxRateError ¶
type MaxRateError struct {
// contains filtered or unexported fields
}
func (*MaxRateError) Error ¶
func (m *MaxRateError) Error() string
type RateErrHandler ¶
type RateErrHandler struct { }
func (*RateErrHandler) ServeHTTP ¶
func (e *RateErrHandler) ServeHTTP(w http.ResponseWriter, req *http.Request, err error)
type RateExtractorFunc ¶
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 New ¶
func New(next http.Handler, extract utils.SourceExtractor, defaultRates *RateSet, opts ...TokenLimiterOption) (*TokenLimiter, error)
New constructs a `TokenLimiter` middleware instance.
func (*TokenLimiter) ServeHTTP ¶
func (tl *TokenLimiter) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*TokenLimiter) Wrap ¶
func (tl *TokenLimiter) Wrap(next http.Handler)
type TokenLimiterOption ¶
type TokenLimiterOption func(l *TokenLimiter) error
func Capacity ¶
func Capacity(cap int) TokenLimiterOption
func Clock ¶
func Clock(clock timetools.TimeProvider) TokenLimiterOption
func ErrorHandler ¶
func ErrorHandler(h utils.ErrorHandler) TokenLimiterOption
ErrorHandler sets error handler of the server
func ExtractRates ¶
func ExtractRates(e RateExtractor) TokenLimiterOption
func Logger ¶
func Logger(l utils.Logger) TokenLimiterOption
Logger sets the logger that will be used by this middleware.
Click to show internal directories.
Click to hide internal directories.