limit

package
v0.0.0-...-a5469ec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2015 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Interfaces for request limiting

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapClientIp

func MapClientIp(req request.Request) (string, int64, error)

MapClientIp creates a mapper that allows rate limiting of requests per client ip

func MapRequestHost

func MapRequestHost(req request.Request) (string, int64, error)

func RequestToBytes

func RequestToBytes(req request.Request) (int64, error)

Maps request to it's size in bytes

func RequestToClientIp

func RequestToClientIp(req request.Request) (string, error)

RequestToClientIp is a TokenMapper that maps the request to the client IP.

func RequestToCount

func RequestToCount(req request.Request) (int64, error)

RequestToCount maps request to the amount of requests (essentially one)

func RequestToHost

func RequestToHost(req request.Request) (string, error)

RequestToHost maps request to the host value

Types

type AmountMapperFn

type AmountMapperFn func(r request.Request) (amount int64, err error)

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

type MapperFn func(r request.Request) (token string, amount int64, err error)

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 MakeMapRequestHeader(header string) MapperFn

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

func VariableToMapper(variable string) (MapperFn, error)

type TokenMapperFn

type TokenMapperFn func(r request.Request) (token string, err error)

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL