Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/resilient/ratelimit

ratelimit

go
import "gitlab.soludian.com/soludian/fountain/libs/resilient/ratelimit"

Index

Variables

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

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

func NewDelayingLimiter

go
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

go
func NewErroringLimiter(limit AllowInf) 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.

type AllowInf

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

go
type AllowInf interface {
    Allow() bool
}

type AllowInfFunc

AllowInfFunc is an adapter that lets a function operate as if it implements AllowInf

go
type AllowInfFunc func() bool

func (AllowInfFunc) Allow

go
func (f AllowInfFunc) Allow() bool

Allow makes the adapter implement AllowInf

type Waiter

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.

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

type WaiterFunc

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

go
type WaiterFunc func(ctx context.Context) error

func (WaiterFunc) Wait

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

Wait makes the adapter implement Waiter

Generated by gomarkdoc