ratelimiter

package
v0.0.0-...-e105d0e Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Type             string `yaml:"type" json:"type,omitempty" mapstructure:"type" default:"sliding_window"`
	DurationInSecond int    `yaml:"duration_in_seconds" json:"duration_in_seconds,omitempty" mapstructure:"duration_in_seconds" default:"1"`
	NumberOfRequests int    `yaml:"number_of_requests" json:"number_of_requests,omitempty" mapstructure:"number_of_requests" default:"20"`
}

type IRateLimiter

type IRateLimiter interface {
	Validate(key string) bool
}

func NewSlidingWindowRateLimiter

func NewSlidingWindowRateLimiter(rdb *redis.Client, logger *slog.Logger, rate *Rate) IRateLimiter

type Rate

type Rate struct {
	Period time.Duration
	Limit  int
}

func NewRate

func NewRate(duration, limit int) *Rate

type RateLimiter

type RateLimiter struct {
	Limiter IRateLimiter
}

func NewRateLimiter

func NewRateLimiter(rdb *redis.Client, logger *slog.Logger, rate *Rate, rltype string) *RateLimiter

type SlidingWindowCache

type SlidingWindowCache interface {
	Validate(keyname string, timestamp int64, window_start int64, limit int) bool
}

func NewRedisLogCache

func NewRedisLogCache(logger *slog.Logger, client *redis.Client) SlidingWindowCache

type SlidingWindowRateLimiter

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

func (*SlidingWindowRateLimiter) Validate

func (t *SlidingWindowRateLimiter) Validate(key string) bool

Jump to

Keyboard shortcuts

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