Documentation
¶
Index ¶
- func GenerateBaseKey(ip string, path string) string
- func GenerateKey(ip string, path string) string
- func GenerateKeyWithWindow(ip string, path string, window int) string
- type Limiter
- func (l *Limiter) Check(ctx context.Context, key string, window int, max int) (remaining int, allowed bool, err error)
- func (l *Limiter) CheckWithAlgorithm(ctx context.Context, key string, window int, max int, algorithm string) (remaining int, allowed bool, err error)
- func (l *Limiter) GetCount(ctx context.Context, key string) (int, error)
- func (l *Limiter) Reset(ctx context.Context, key string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateBaseKey ¶
GenerateBaseKey creates a base rate limit key without time component This is used for sliding window algorithm which manages time slots internally
func GenerateKey ¶
GenerateKey creates a rate limit key from IP address and path
Types ¶
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter provides rate limiting functionality using secondary storage
func NewLimiter ¶
func NewLimiter(secondary storage.SecondaryStorage) *Limiter
NewLimiter creates a new rate limiter
func (*Limiter) Check ¶
func (l *Limiter) Check(ctx context.Context, key string, window int, max int) (remaining int, allowed bool, err error)
Check checks if a request should be allowed based on rate limits Returns remaining requests and whether the request should be allowed
func (*Limiter) CheckWithAlgorithm ¶
func (l *Limiter) CheckWithAlgorithm(ctx context.Context, key string, window int, max int, algorithm string) (remaining int, allowed bool, err error)
CheckWithAlgorithm checks if a request should be allowed based on rate limits using the specified algorithm Returns remaining requests and whether the request should be allowed
Click to show internal directories.
Click to hide internal directories.