ratelimit

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client can connect to gubernator and get rate limits.

func NewClient

func NewClient(reg prometheus.Registerer) *Client

NewClient creates a new gubernator client with default configuration.

func (*Client) Dial

func (c *Client) Dial(ctx context.Context, address string) error

Dial connects the client to gubernator.

func (*Client) GetRateLimits

func (c *Client) GetRateLimits(ctx context.Context, req *request) (remaining, resetTime int64, err error)

GetRateLimits gets the rate limits corresponding to a request. Note: Dial must be called before calling this method, otherwise the client will panic.

type Config

type Config struct {
	Tenant  string
	Matcher *regexp.Regexp
	Limit   int
	Window  time.Duration
}

Config configures a rate limiter per endpoint, per tenant.

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware is a convenience type for functions that wrap http.Handlers.

func WithLocalRateLimiter

func WithLocalRateLimiter(configs ...Config) Middleware

WithLocalRateLimiter returns a middleware that controls the amount of requests per tenant using an in-memory store.

func WithSharedRateLimiter

func WithSharedRateLimiter(logger log.Logger, client *Client, configs ...Config) Middleware

WithSharedRateLimiter returns a middleware that controls the amount of requests per tenant using an external service.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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