rrate

package
v0.7.4 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	MaxRetries: 10,
}

DefaultConfig is the configuration which is used by default

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 (*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

	// Config returns the Config the rate limiter uses
	Config() Config

	// 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)

	// 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(config *Config) 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