-- import "go-ratelimit/ratelimit"
type RateLimitConfig struct {
Attempts int
WindowInSeconds int
CooldownInSeconds int
}RateLimitConfig type for setting rate limiting params
func NewRateLimitConfig(attempts, windowInSeconds, cooldownInSeconds int) *RateLimitConfigNewRateLimitConfig to create a new config for rate limiting
var ErrBlocked = errors.New("rate limit: blocked")ErrBlocked is returned when an attribute is rate limited
type RateLimit struct {
}RateLimit type for ratelimiting
func NewRateLimit(redisPool *redis.Pool, config *config.RateLimitConfig) *RateLimitNewRateLimit func to create a new rate limiting type
func (rl *RateLimit) RateLimitExceeded(key string) boolRateLimitExceeded returns state of a RateLimit for a key given
func (rl *RateLimit) Reset(key string) errorReset func clears the key from rate limiting
func (rl *RateLimit) Run(key string) errorRun initiates ratelimiting for the key given
type RateLimiter interface {
Run(key string) error
RateLimitExceeded(key string) bool
Reset(key string) error
}RateLimiter interface for rate limiting key