throttle

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2023 License: MIT Imports: 2 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

type Group struct {
	// contains filtered or unexported fields
}

Group represents a slice of constraints that must all be satisfied to succeed.

func NewGroup

func NewGroup(l ...Limiter) *Group

NewGroup returns a new group of Limiters.

func (*Group) Wait

func (l *Group) Wait(ctx context.Context) error

Wait invoke the Wait method of all limiters concurrently.

type Limiter

type Limiter interface {
	Wait(context.Context) error
}

Limiter describes a common interface to describe the constraint on a request. If the constrain is satified then the request can continue.

type LimiterFunc

type LimiterFunc func(context.Context) error

LimiterFunc is an adapter to allow the use of functions without a receiver as limiters. If `f` is a function with the appropriate signature, LimiterFunc(f) is a Limiter that calls `f`.

func (LimiterFunc) Wait

func (f LimiterFunc) Wait(ctx context.Context) error

Wait calls the underlying function reprsented by the receiver of this method.

type Transport

type Transport struct {
	Transport http.RoundTripper // Used to make actual requests.
	// contains filtered or unexported fields
}

Transport implements http.RoundTripper and throttles requests described by the constraints of one or more Limiter values.

func New

func New(transport http.RoundTripper, l ...Limiter) *Transport

New returns a RoundTripper that throttles HTTP requests.

func NewWithDefaultTransport

func NewWithDefaultTransport(l ...Limiter) *Transport

NewWithDefaultTransport returns a RoundTripper that throttles HTTP requests.

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip ensures requests are executed within the limiting constraints.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL