ratelimit

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package ratelimit implements rate limiting.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InMemoryLimiter

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

InMemoryLimiter implements RateLimiter using an in-memory map.

func NewInMemoryLimiter

func NewInMemoryLimiter() *InMemoryLimiter

NewInMemoryLimiter creates a new rate limiter.

func (*InMemoryLimiter) Allow

Allow checks if the request is allowed.

func (*InMemoryLimiter) Consume

func (r *InMemoryLimiter) Consume(ctx context.Context, key ratelimit.RateLimitKey, tokens int64) error

Consume deducts tokens from the quota.

func (*InMemoryLimiter) Remaining

func (r *InMemoryLimiter) Remaining(ctx context.Context, key ratelimit.RateLimitKey) (int64, error)

Remaining returns the remaining quota.

func (*InMemoryLimiter) Reset

Reset resets the quota for a key.

func (*InMemoryLimiter) SetQuota

func (r *InMemoryLimiter) SetQuota(ctx context.Context, tenantID string, config *ratelimit.QuotaConfig) error

SetQuota sets the quota config for a tenant.

type RedisLimiter

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

RedisLimiter implements RateLimiter using Redis.

func NewRedisLimiter

func NewRedisLimiter(client *redis.Client) *RedisLimiter

NewRedisLimiter creates a new Redis rate limiter.

func (*RedisLimiter) Allow

Allow checks if the request is allowed.

func (*RedisLimiter) Consume

func (r *RedisLimiter) Consume(ctx context.Context, key ratelimit.RateLimitKey, tokens int64) error

Consume deducts tokens from the quota.

func (*RedisLimiter) Remaining

func (r *RedisLimiter) Remaining(ctx context.Context, key ratelimit.RateLimitKey) (int64, error)

Remaining returns the remaining quota.

func (*RedisLimiter) Reset

Reset resets the quota for a key.

func (*RedisLimiter) SetQuota

func (r *RedisLimiter) SetQuota(ctx context.Context, tenantID string, config *ratelimit.QuotaConfig) error

SetQuota stores the quota config in Redis.

Jump to

Keyboard shortcuts

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