Documentation ¶
Overview ¶
Interfaces for request limiting
Index ¶
- func MapClientIp(req request.Request) (string, int64, error)
- func MapRequestHost(req request.Request) (string, int64, error)
- func RequestToBytes(req request.Request) (int64, error)
- func RequestToClientIp(req request.Request) (string, error)
- func RequestToCount(req request.Request) (int64, error)
- func RequestToHost(req request.Request) (string, error)
- type AmountMapperFn
- type Limiter
- type MapperFn
- type TokenMapperFn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MapClientIp ¶
MapClientIp creates a mapper that allows rate limiting of requests per client ip
func RequestToBytes ¶
Maps request to it's size in bytes
func RequestToClientIp ¶
RequestToClientIp is a TokenMapper that maps the request to the client IP.
func RequestToCount ¶
RequestToCount maps request to the amount of requests (essentially one)
Types ¶
type AmountMapperFn ¶
AmountMapperFn maps the request to the amount of tokens to consume
type Limiter ¶
type Limiter interface { // In case if limiter wants to reject request, it should return http response // will be proxied to the client. // In case if limiter returns an error, it will be treated as a request error and will // potentially activate failure recovery and failover algorithms. // In case if lmimiter wants to delay request, it should return duration > 0 // Otherwise limiter should return (0, nil) to allow request to proceed middleware.Middleware }
Limiter is an interface for request limiters (e.g. rate/connection) limiters
type MapperFn ¶
MapperFn takes the request and returns token that corresponds to the request and the amount of tokens this request is going to consume, e.g. * Client ip rate limiter - token is a client ip, amount is 1 request * Client ip bandwidth limiter - token is a client ip, amount is number of bytes to consume In case of error returns non nil error, in this case rate limiter will reject the request.
func MakeMapRequestHeader ¶
func MakeMapper ¶
func MakeMapper(t TokenMapperFn, a AmountMapperFn) MapperFn
Make mapper constructs the mapper function out of two functions - token mapper and amount mapper
func VariableToMapper ¶
type TokenMapperFn ¶
TokenMapperFn maps the request to limiting token
func MakeRequestToHeader ¶
func MakeRequestToHeader(header string) TokenMapperFn
MakeTokenMapperByHeader creates a TokenMapper that maps the incoming request to the header value.
func MakeTokenMapperFromVariable ¶
func MakeTokenMapperFromVariable(variable string) (TokenMapperFn, error)
Converts varaiable string to a mapper function used in limiters
Directories ¶
Path | Synopsis |
---|---|
Simultaneous connection limiter
|
Simultaneous connection limiter |
Tokenbucket based request rate limiter
|
Tokenbucket based request rate limiter |