ratelimit

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Decision

type Decision struct {
	Allowed           bool
	RetryAfterSeconds int
	Remaining         float64
	LimitRPS          float64
	Burst             float64
}

type Limiter

type Limiter interface {
	Allow(ctx context.Context, key string, rps float64, burst float64, cost float64) (Decision, error)
	Close() error
}

type MemoryLimiter

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

func NewMemoryLimiter

func NewMemoryLimiter(ttl time.Duration, cleanupEvery time.Duration) *MemoryLimiter

func (*MemoryLimiter) Allow

func (m *MemoryLimiter) Allow(ctx context.Context, key string, rps float64, burst float64, cost float64) (Decision, error)

func (*MemoryLimiter) Close

func (m *MemoryLimiter) Close() error

type RedisLimiter

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

func NewRedisLimiter

func NewRedisLimiter(rdb *redis.Client) *RedisLimiter

func (*RedisLimiter) Allow

func (r *RedisLimiter) Allow(ctx context.Context, key string, rps float64, burst float64, cost float64) (Decision, error)

func (*RedisLimiter) Close

func (r *RedisLimiter) Close() error

Jump to

Keyboard shortcuts

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