ratelimiter_bloom

package
v0.0.0-...-036a4ef Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BloomFilterCounter

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

BloomFilterCounter implements a Bloom filter counter.

func NewBloomFilterCounter

func NewBloomFilterCounter(size uint32, capacity ...uint32) *BloomFilterCounter

NewBloomFilterCounter creates a new Bloom filter counter with the specified size. The default capacity is set to 10 if not specified.

func (*BloomFilterCounter) CheckCount

func (bfc *BloomFilterCounter) CheckCount(key string) int

CheckCount checks the count for the given key.

func (*BloomFilterCounter) Counter

func (bfc *BloomFilterCounter) Counter(key string) uint32

Counter returns the counter value for the given key.

func (*BloomFilterCounter) Decrement

func (bfc *BloomFilterCounter) Decrement(key string, count int)

Decrement decrements the counter for the given key by the specified count.

func (*BloomFilterCounter) DecrementWithRetry

func (bfc *BloomFilterCounter) DecrementWithRetry(key string, count int)

DecrementWithRetry attempts to decrement the counter for the given key with retry logic. It prevents the counter from going below zero.

func (*BloomFilterCounter) DecrementWithRetryDecorator

func (bfc *BloomFilterCounter) DecrementWithRetryDecorator(fn MutatorFunc) MutatorFunc

func (*BloomFilterCounter) Increment

func (bfc *BloomFilterCounter) Increment(key string, count int)

Increment increments the counter for the given key by the specified count.

func (*BloomFilterCounter) IncrementWithRetry

func (bfc *BloomFilterCounter) IncrementWithRetry(key string, count int)

IncrementWithRetry increments the counter for the given key by the specified count with retry logic.

func (*BloomFilterCounter) IncrementWithRetryDecorator

func (bfc *BloomFilterCounter) IncrementWithRetryDecorator(fn MutatorFunc) MutatorFunc

Decorator function that adds retry logic

func (*BloomFilterCounter) IsEmpty

func (bfc *BloomFilterCounter) IsEmpty(key string) bool

IsEmpty checks if the counter for the given key is greater than 0.

type Bucket

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

Bucket struct that contains the counter array and timestamp.

type MutatorFunc

type MutatorFunc func(key string, count int)

Function type for mutator functions

type RateLimitEvent

type RateLimitEvent struct {
	Key                 string
	Timestamp           time.Time
	Message             string
	ExpirationTimestamp time.Time
}

RateLimitEvent represents an event when the bucket is exhausted.

type RateLimiter

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

RateLimiter controls the rate of requests using a leaky bucket algorithm

func NewRateLimiter

func NewRateLimiter(capacity uint32, rate int) *RateLimiter

NewRateLimiter creates a new RateLimiter with the specified capacity and refill rate

func (*RateLimiter) AddListener

func (rl *RateLimiter) AddListener(listener event.EventListener)

AddListener adds an event listener to the rate limiter.

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(key string) bool

Allow checks if a request can be processed

func (*RateLimiter) Shutdown

func (rl *RateLimiter) Shutdown(ctx context.Context) error

Shutdown stops the event publisher and waits for it to finish.

type Storekeeper

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

Storekeeper is an implementation of EventListener that handles rate limit events.

func NewStorekeeper

func NewStorekeeper(eventPublisher *event.BaseEventPublisher) *Storekeeper

NewStorekeeper creates a new Storekeeper.

func (*Storekeeper) HandleEvent

func (sk *Storekeeper) HandleEvent(ctx context.Context, e event.Event) error

HandleEvent processes rate limit events.

Jump to

Keyboard shortcuts

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