ratelimiter

package module
v0.0.0-...-d071872 Latest Latest
Warning

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

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

README

rolling-rate-limiter

a golang rolling rate limiter package, based on redis

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenRateConfigForLimiter

func ListenRateConfigForLimiter(channel string, pool *resourcepool.ResourcePool,
	limiter *RedisRollingRateLimiter) error

ListenRateConfigForLimiter subscribes on a channel, and configure limiter on RateConfig message

Types

type RateConfig

type RateConfig struct {
	Rate     int `json:"rate"`
	Interval int `json:"interval"`
}

type RedisRollingRateLimiter

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

RedisRollingRateLimiter

func NewRedisRollingRateLimiter

func NewRedisRollingRateLimiter(prefix string, redisPool *resourcepool.ResourcePool, interval, rate int) *RedisRollingRateLimiter

func (RedisRollingRateLimiter) Check

func (l RedisRollingRateLimiter) Check(key string) bool

func (RedisRollingRateLimiter) Reset

func (l RedisRollingRateLimiter) Reset(key string)

type RollingRateLimiter

type RollingRateLimiter interface {
	Check(key string) bool
	Reset(key string)
}

RollingRateLimiter interface makes it easier to do unit testing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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