ratelimit

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2017 License: MIT Imports: 5 Imported by: 539

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLimited = errors.New("rate limit exceeded")

ErrLimited is returned in the request path when the rate limiter is triggered and the request is rejected.

Functions

func NewDelayingLimiter added in v0.6.0

func NewDelayingLimiter(limit Waiter) endpoint.Middleware

NewDelayingLimiter returns an endpoint.Middleware that acts as a request throttler. Requests that would exceed the maximum request rate are delayed via the Waiter function

func NewErroringLimiter added in v0.6.0

func NewErroringLimiter(limit Allower) endpoint.Middleware

NewErroringLimiter returns an endpoint.Middleware that acts as a rate limiter. Requests that would exceed the maximum request rate are simply rejected with an error.

func NewTokenBucketLimiter

func NewTokenBucketLimiter(tb *ratelimit.Bucket) endpoint.Middleware

NewTokenBucketLimiter returns an endpoint.Middleware that acts as a rate limiter based on a token-bucket algorithm. Requests that would exceed the maximum request rate are simply rejected with an error.

func NewTokenBucketThrottler

func NewTokenBucketThrottler(tb *ratelimit.Bucket, _ func(time.Duration)) endpoint.Middleware

NewTokenBucketThrottler returns an endpoint.Middleware that acts as a request throttler based on a token-bucket algorithm. Requests that would exceed the maximum request rate are delayed. The parameterized function "_" is kept for backwards-compatiblity of the API, but it is no longer used for anything. You may pass it nil.

Types

type Allower added in v0.6.0

type Allower interface {
	Allow() bool
}

Allower dictates whether or not a request is acceptable to run. The Limiter from "golang.org/x/time/rate" already implements this interface, one is able to use that in NewErroringLimiter without any modifications.

func NewAllower added in v0.6.0

func NewAllower(tb *ratelimit.Bucket) Allower

NewAllower turns an existing ratelimit.Bucket into an API-compatible form

type AllowerFunc added in v0.6.0

type AllowerFunc func() bool

AllowerFunc is an adapter that lets a function operate as if it implements Allower

func (AllowerFunc) Allow added in v0.6.0

func (f AllowerFunc) Allow() bool

Allow makes the adapter implement Allower

type Waiter added in v0.6.0

type Waiter interface {
	Wait(ctx context.Context) error
}

Waiter dictates how long a request must be delayed. The Limiter from "golang.org/x/time/rate" already implements this interface, one is able to use that in NewDelayingLimiter without any modifications.

func NewWaiter added in v0.6.0

func NewWaiter(tb *ratelimit.Bucket) Waiter

NewWaiter turns an existing ratelimit.Bucket into an API-compatible form

type WaiterFunc added in v0.6.0

type WaiterFunc func(ctx context.Context) error

WaiterFunc is an adapter that lets a function operate as if it implements Waiter

func (WaiterFunc) Wait added in v0.6.0

func (f WaiterFunc) Wait(ctx context.Context) error

Wait makes the adapter implement Waiter

Jump to

Keyboard shortcuts

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