ratelimit

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package ratelimit defines common rate limiting logic and config.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RateLimiterFor

func RateLimiterFor(ctx context.Context, c *Config) (limiter.Store, error)

RateLimiterFor returns the rate limiter for the given type, or an error if one does not exist.

Types

type Config

type Config struct {
	// Common configuration
	Type     Type          `env:"RATE_LIMIT_TYPE, default=NOOP"`
	Tokens   uint64        `env:"RATE_LIMIT_TOKENS, default=120"`
	Interval time.Duration `env:"RATE_LIMIT_INTERVAL, default=1m"`

	// HMACKey is the key to use when calculating the HMAC of keys before saving
	// them in the rate limiter.
	HMACKey envconfig.Base64Bytes `env:"RATE_LIMIT_HMAC_KEY, required"`

	// Redis configuration
	Redis redis.Config `env:",prefix=RATE_LIMIT_"`
}

Config represents rate limiting configuration

type Type added in v0.22.0

type Type string

Type represents a type of rate limiter.

const (
	RateLimiterTypeNoop   Type = "NOOP"
	RateLimiterTypeMemory Type = "MEMORY"
	RateLimiterTypeRedis  Type = "REDIS"
)

Directories

Path Synopsis
Package limitware provides middleware for rate limiting HTTP handlers.
Package limitware provides middleware for rate limiting HTTP handlers.

Jump to

Keyboard shortcuts

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