Documentation ¶
Index ¶
- type BloomFilterCounter
- func (bfc *BloomFilterCounter) CheckCount(key string) int
- func (bfc *BloomFilterCounter) Counter(key string) uint32
- func (bfc *BloomFilterCounter) Decrement(key string, count int)
- func (bfc *BloomFilterCounter) DecrementWithRetry(key string, count int)
- func (bfc *BloomFilterCounter) DecrementWithRetryDecorator(fn MutatorFunc) MutatorFunc
- func (bfc *BloomFilterCounter) Increment(key string, count int)
- func (bfc *BloomFilterCounter) IncrementWithRetry(key string, count int)
- func (bfc *BloomFilterCounter) IncrementWithRetryDecorator(fn MutatorFunc) MutatorFunc
- func (bfc *BloomFilterCounter) IsEmpty(key string) bool
- type Bucket
- type MutatorFunc
- type RateLimitEvent
- type RateLimiter
- type Storekeeper
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 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
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 ¶
HandleEvent processes rate limit events.