ratelimit

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2020 License: Apache-2.0 Imports: 9 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(_ 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"`
	FailureMode string        `env:"RATE_LIMIT_FAILURE_MODE,default=closed"`

	// Redis configuration
	RedisHost     string `env:"REDIS_HOST,default=127.0.0.1"`
	RedisPort     string `env:"REDIS_PORT,default=6379"`
	RedisUsername string `env:"REDIS_USERNAME"`
	RedisPassword string `env:"REDIS_PASSWORD"`
	RedisMinPool  uint64 `env:"REDIS_MIN_POOL,default=16"`
	RedisMaxPool  uint64 `env:"REDIS_MAX_POOL,default=64"`
}

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

Jump to

Keyboard shortcuts

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