ratelimit

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 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     RateLimitType `env:"RATE_LIMIT_TYPE, default=NOOP"`
	Tokens   uint64        `env:"RATE_LIMIT_TOKENS, default=60"`
	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 RateLimitType

type RateLimitType string

RateLimitType represents a type of rate limiter.

const (
	RateLimiterTypeNoop   RateLimitType = "NOOP"
	RateLimiterTypeMemory RateLimitType = "MEMORY"
	RateLimiterTypeRedis  RateLimitType = "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