ratelimit

package module
v2.2.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README

Build Status

ratelimit

-- import "go-ratelimit/ratelimit"

Usage

type RateLimitConfig
type RateLimitConfig struct {
	Attempts          int
	WindowInSeconds   int
	CooldownInSeconds int
}

RateLimitConfig type for setting rate limiting params

func NewRateLimitConfig
func NewRateLimitConfig(attempts, windowInSeconds, cooldownInSeconds int) *RateLimitConfig

NewRateLimitConfig to create a new config for rate limiting

var ErrBlocked = errors.New("rate limit: blocked")

ErrBlocked is returned when an attribute is rate limited

type RateLimit
type RateLimit struct {
}

RateLimit type for ratelimiting

func NewRateLimit
func NewRateLimit(redisPool *redis.Pool, config *config.RateLimitConfig) *RateLimit

NewRateLimit func to create a new rate limiting type

func (*RateLimit) RateLimitExceeded
func (rl *RateLimit) RateLimitExceeded(key string) bool

RateLimitExceeded returns state of a RateLimit for a key given

func (*RateLimit) Reset
func (rl *RateLimit) Reset(key string) error

Reset func clears the key from rate limiting

func (*RateLimit) Run
func (rl *RateLimit) Run(key string) error

Run initiates ratelimiting for the key given

type RateLimiter
type RateLimiter interface {
	Run(key string) error
	RateLimitExceeded(key string) bool
	Reset(key string) error
}

RateLimiter interface for rate limiting key

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlocked = errors.New("rate limit: blocked")

ErrBlocked is returned when an attribute is rate limited

Functions

This section is empty.

Types

type RateLimit

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

RateLimit type for ratelimiting

func NewRateLimit

func NewRateLimit(redisPool *redis.Pool, config *RateLimitConfig) *RateLimit

NewRateLimit func to create a new rate limiting type

func (*RateLimit) RateLimitExceeded

func (rl *RateLimit) RateLimitExceeded(key string) bool

RateLimitExceeded returns state of a RateLimit for a key given

func (*RateLimit) Reset

func (rl *RateLimit) Reset(key string) error

Reset func clears the key from rate limiting

func (*RateLimit) Run

func (rl *RateLimit) Run(key string) error

Run initiates ratelimiting for the key given

type RateLimitConfig

type RateLimitConfig struct {
	Attempts          int
	WindowInSeconds   int
	CooldownInSeconds int
}

RateLimitConfig type for setting rate limiting params

func NewRateLimitConfig

func NewRateLimitConfig(attempts, windowInSeconds, cooldownInSeconds int) *RateLimitConfig

NewRateLimitConfig to create a new config for rate limiting

type RateLimiter

type RateLimiter interface {
	Run(key string) error
	RateLimitExceeded(key string) bool
	Reset(key string) error
}

RateLimiter interface for rate limiting key

Jump to

Keyboard shortcuts

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