ratelimit

package
v0.0.0-...-7264f90 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: MIT Imports: 3 Imported by: 0

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

func NewDelayingLimiter[O interface{}](limit Waiter) endpoint.Middleware[O]

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

func NewErroringLimiter[O interface{}](limit Allower) endpoint.Middleware[O]

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.

Types

type Allower

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.

type AllowerFunc

type AllowerFunc func() bool

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

func (AllowerFunc) Allow

func (f AllowerFunc) Allow() bool

Allow makes the adapter implement Allower

type Waiter

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.

type WaiterFunc

type WaiterFunc func(ctx context.Context) error

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

func (WaiterFunc) Wait

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