ratelimit

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Take

func Take(ctx context.Context, l Limiter)

Take is a helper function that calls the Take method on a Limiter. It is used to apply rate limiting to an operation.

Types

type Limiter

type Limiter interface {
	Take(ctx context.Context) time.Duration
}

Limiter is an interface for rate limiting functionality. It defines a method for taking a rate-limited action.

func NewLocalLimiter

func NewLocalLimiter(maximumRPS int, burstableRPS int) Limiter

NewLocalLimiter creates a new local rate limiter with specified maximum and burstable requests per second.

func NewRedisLimiter

func NewRedisLimiter(redisClient *redis.Client, maxRPS int) Limiter

NewRedisLimiter creates a new Redis-based rate limiter.

type Local

type Local struct {
	*rate.Limiter // Embedded rate limiter from the rate package
}

Local represents a local rate limiter using the golang.org/x/time/rate package.

func (Local) Take

func (l Local) Take(ctx context.Context) time.Duration

Take attempts to allow an action under the rate limit and returns the duration taken.

type Redis

type Redis struct {
	*redis_rate.Limiter     // Embedded Redis rate limiter
	MaxRPS              int // Maximum requests per second allowed
}

Redis represents a rate limiter using Redis.

func (Redis) Take

func (r Redis) Take(ctx context.Context) time.Duration

Take attempts to allow a request under the rate limit and blocks until allowed.

Jump to

Keyboard shortcuts

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