ratelimit

package
v0.44.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Default = redis_rate.PerMinute(180)
View Source
var Public = redis_rate.PerMinute(750)
View Source
var Sensitive = redis_rate.PerMinute(30)
View Source
var Unlimited = redis_rate.PerSecond(math.MaxInt)
View Source
var Zero = redis_rate.Limit{}

Functions

func AnonLimitKey

func AnonLimitKey(methodName, peer string) string

func AuthLimitKey

func AuthLimitKey(methodName, authID string) string

Types

type Limiter

type Limiter interface {
	Limit(ctx context.Context, limitKey string, limit redis_rate.Limit) error
}

Limiter returns an error if quota per key is exceeded.

type Noop

type Noop struct{}

Noop performs no rate limiting. This can be useful in local/testing environments or when rate limiting is not required.

func NewNoop

func NewNoop() *Noop

func (Noop) Limit

func (n Noop) Limit(ctx context.Context, limitKey string, limit redis_rate.Limit) error

type QuotaExceededError

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

func NewQuotaExceededError

func NewQuotaExceededError(message string) QuotaExceededError

func (QuotaExceededError) Error

func (e QuotaExceededError) Error() string

type Redis

type Redis struct {
	*redis_rate.Limiter
}

Redis offers rate limiting functionality using a Redis-based rate limiter.

func NewRedis

func NewRedis(client *redis.Client) *Redis

func (*Redis) Limit

func (l *Redis) Limit(ctx context.Context, limitKey string, limit redis_rate.Limit) error

Jump to

Keyboard shortcuts

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