ratelimit - ActiveState ActiveGo 1.8
...

Package ratelimit

import "github.com/go-kit/kit/ratelimit"
Overview
Index

Overview ▾

Variables

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

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

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, sleep 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 via the parameterized sleep function. By default you may pass time.Sleep.