rrate

package
v0.11.5 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Logger     log.Logger
	MaxRetries int
}

Config is the configuration for the rate limiter

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is the configuration which is used by default

func (*Config) Apply

func (c *Config) Apply(opts []ConfigOpt)

Apply applies the given ConfigOpt(s) to the Config

type ConfigOpt

type ConfigOpt func(config *Config)

ConfigOpt can be used to supply optional parameters to NewLimiter

func WithLogger

func WithLogger(logger log.Logger) ConfigOpt

WithLogger applies a custom logger to the rest rate limiter

func WithMaxRetries

func WithMaxRetries(maxRetries int) ConfigOpt

WithMaxRetries tells the rest rate limiter to retry the request up to the specified number of times if it encounters a 429 response

type Limiter

type Limiter interface {
	// Logger returns the logger the rate limiter uses
	Logger() log.Logger

	// MaxRetries returns the maximum number of retries the client should do
	MaxRetries() int

	// Close closes the rate limiter and awaits all pending requests to finish. You can use a cancelling context to abort the waiting
	Close(ctx context.Context)

	// Reset resets the rate limiter to its initial state
	Reset()

	// WaitBucket waits for the given bucket to be available for new requests & locks it
	WaitBucket(ctx context.Context, route *route.CompiledAPIRoute) error

	// UnlockBucket unlocks the given bucket and calculates the rate limit for the next request
	UnlockBucket(route *route.CompiledAPIRoute, headers http.Header) error
}

Limiter can be used to supply your own rate limit implementation

func NewLimiter

func NewLimiter(opts ...ConfigOpt) Limiter

NewLimiter return a new default implementation of a rest rate limiter

Jump to

Keyboard shortcuts

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