rate_limiter

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: GPL-3.0 Imports: 6 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// RateLimiterPrefix is the prefix of the rate limiter key
	RateLimiterPrefix = "rate_limiter"
)

Variables

View Source
var (
	TooManyRequestsError = errors.New("too many requests")
	NilRateLimiterError  = errors.New("nil rate limiter")
)

Functions

This section is empty.

Types

type DefaultRateLimiter

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

DefaultRateLimiter struct

func NewDefaultRateLimiter

func NewDefaultRateLimiter(redisClient *redis.Client, limit int, period time.Duration) (*DefaultRateLimiter, error)

NewDefaultRateLimiter creates a new rate limiter

func (*DefaultRateLimiter) GetKey added in v0.6.1

func (d *DefaultRateLimiter) GetKey(ip string) string

GetKey gets the rate limiter key

func (*DefaultRateLimiter) Limit

func (d *DefaultRateLimiter) Limit(ip string) error

Limit limits the rate of requests

func (*DefaultRateLimiter) SetInitialValue added in v0.6.1

func (d *DefaultRateLimiter) SetInitialValue(key string) error

SetInitialValue sets the initial value for the given key

type RateLimiter

type RateLimiter interface {
	Limit(ip string) error
}

RateLimiter interface

Jump to

Keyboard shortcuts

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