ratelimiter

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsInvalidConfig

func IsInvalidConfig(err error) bool

IsInvalidConfig asserts invalidConfigError.

func IsLimitReached

func IsLimitReached(err error) bool

IsLimitReached asserts limitReachedError.

Types

type Config

type Config struct {
	Logger micrologger.Logger

	// DefaultLimit is the default rate limit for all rate limiters. It is
	// currently not possible to specify a rate limit per endpoint.
	DefaultLimit int64
	// DefaultPeriod is the default period for all rate limiters. It is currently
	// not possible to specify a period per endpoint.
	DefaultPeriod time.Duration
}

type LookupFunc

type LookupFunc func(ctx context.Context, request interface{}) (string, error)

LookupFunc is the middleware configuration required to lookup the rate limit key of the user making the current request. This has to be configured independently since the rate limit key is provided differently with each endpoint.

type Middleware

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

func New

func New(config Config) (*Middleware, error)

func (*Middleware) New

func (m *Middleware) New(lookupFunc LookupFunc) kitendpoint.Middleware

New takes a function and returns a middleware, unlike other middlewares, it needs to know how to extract some information from the request which might be in different places depending on the endpoint.

Jump to

Keyboard shortcuts

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