Back to

Package ratelimit

Latest Go to latest

The latest major version is .

Published: Jul 29, 2019 | License: MIT | Module:


type Clock

type Clock interface {
	Now() time.Time

Clock is the minimum necessary interface to instantiate a rate limiter with a clock or mock clock, compatible with clocks created using

type Limiter

type Limiter interface {
	// Take should block to make sure that the RPS is met.
	Take() time.Time

Limiter is used to rate-limit some process, possibly across goroutines. The process is expected to call Take() before every iteration, which may block to throttle the goroutine.

func New

func New(rate int, opts ...Option) Limiter

New returns a Limiter that will limit to the given RPS.

func NewUnlimited

func NewUnlimited() Limiter

NewUnlimited returns a RateLimiter that is not limited.

type Option

type Option func(l *limiter)

Option configures a Limiter.

var WithoutSlack Option = withoutSlackOption

WithoutSlack is an option for ratelimit.New that initializes the limiter without any initial tolerance for bursts of traffic.

func WithClock

func WithClock(clock Clock) Option

WithClock returns an option for ratelimit.New that provides an alternate Clock implementation, typically a mock Clock for testing.

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier