ratelimiter

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: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestRateLimiter_Allow

func TestRateLimiter_Allow(t *testing.T)

Types

type RateLimitEvent

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

RateLimitEvent represents an event when both buckets are exhausted.

type RateLimiter

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

RateLimiter controls the rate of requests using a two-bucket leaky bucket algorithm

func NewRateLimiter

func NewRateLimiter(primaryCapacity int, secondaryCapacity int, rate int) *RateLimiter

NewRateLimiter creates a new RateLimiter with the specified capacities 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.

Jump to

Keyboard shortcuts

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