package ratelimit

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

Index

Variables

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 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.

Source Files

token_bucket.go

Version
v0.4.0
Published
Mar 6, 2017
Platform
linux/amd64
Imports
5 packages
Last checked
5 minutes ago

Tools for package owners.