Help us shape the future of Go! Take the 2026 Go Developer Survey

ratelimit

package
v0.89.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

Common rate limit configurations

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
	Ping(ctx context.Context) 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

func (Noop) Ping added in v0.47.0

func (n Noop) Ping(ctx context.Context) 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
	// contains filtered or unexported fields
}

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

func (*Redis) Ping added in v0.47.0

func (l *Redis) Ping(ctx context.Context) error

Jump to

Keyboard shortcuts

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