ratelimit

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: MIT Imports: 3 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RateLimiter

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

Wrapper around Go's rate.Limiter that supports both global and a per-sender rate limiting.

func NewRateLimiter

func NewRateLimiter(config RateLimiterConfig) (*RateLimiter, error)

func (*RateLimiter) Allow

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

Allow checks that the sender is not rate limited, and that there is not a global rate limit.

func (*RateLimiter) AllowVerbose

func (rl *RateLimiter) AllowVerbose(sender string) (senderAllow bool, globalAllow bool)

Allow checks that the sender is not rate limited, and that there is not a global rate limit. Returns if allowed as separate outputs.

type RateLimiterConfig

type RateLimiterConfig struct {
	GlobalRPS      float64 `json:"globalRPS"`
	GlobalBurst    int     `json:"globalBurst"`
	PerSenderRPS   float64 `json:"perSenderRPS"`
	PerSenderBurst int     `json:"perSenderBurst"`
}

Jump to

Keyboard shortcuts

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