helpers

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 4 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiLimiter added in v1.8.0

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

ApiLimiter allows to rate limit API calls

func NewApiLimiter added in v1.8.0

func NewApiLimiter(metrics MetricsAPI, rateLimit float64, burst int) *ApiLimiter

NewApiLimiter returns a new API limiter with the specific rate limit and burst configuration. The MetricsAPI interface is called to allow for metrics accounting.

func (*ApiLimiter) Limit added in v1.8.0

func (l *ApiLimiter) Limit(ctx context.Context, operation string)

Limit applies the rate limiting configuration for the given operation

type DelaySimulator

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

DelaySimulator simulates delays in API calls

func NewDelaySimulator

func NewDelaySimulator() *DelaySimulator

NewDelaySimulator returns a new DelaySimulator

func (*DelaySimulator) Delay

func (d *DelaySimulator) Delay(op Operation)

Delay delays an API operation according to the configuration

func (*DelaySimulator) SetDelay

func (d *DelaySimulator) SetDelay(op Operation, delay time.Duration)

SetDelay specifies the delay to be simulated for an individual API operation

type MetricsAPI

type MetricsAPI interface {
	ObserveRateLimit(operation string, duration time.Duration)
}

MetricsAPI represents the metrics maintained by the API limiter

type Operation

type Operation interface{}

Operation represents an API operation

Jump to

Keyboard shortcuts

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