Import path:
gitlab.soludian.com/soludian/fountain/libs/resilient/ratelimit
ratelimit
import "gitlab.soludian.com/soludian/fountain/libs/resilient/ratelimit"Index
- Variables
- func NewDelayingLimiter(limit Waiter) endpoint.Middleware
- func NewErroringLimiter(limit AllowInf) endpoint.Middleware
- type AllowInf
- type AllowInfFunc
- type Waiter
- type WaiterFunc
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 NewDelayingLimiter
func NewDelayingLimiter(limit Waiter) endpoint.MiddlewareNewDelayingLimiter 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(limit AllowInf) endpoint.MiddlewareNewErroringLimiter 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.
type AllowInf interface {
Allow() bool
}type AllowInfFunc
AllowInfFunc is an adapter that lets a function operate as if it implements AllowInf
type AllowInfFunc func() boolfunc (AllowInfFunc) Allow
func (f AllowInfFunc) Allow() boolAllow 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.
type Waiter interface {
Wait(ctx context.Context) error
}type WaiterFunc
WaiterFunc is an adapter that lets a function operate as if it implements Waiter
type WaiterFunc func(ctx context.Context) errorfunc (WaiterFunc) Wait
func (f WaiterFunc) Wait(ctx context.Context) errorWait makes the adapter implement Waiter
Generated by gomarkdoc