Documentation ¶
Index ¶
Constants ¶
View Source
const (
// RateLimiterPrefix is the prefix of the rate limiter key
RateLimiterPrefix = "rate_limiter"
)
Variables ¶
View Source
var ( TooManyRequestsError = errors.New("too many requests") NilRateLimiterError = errors.New("nil rate limiter") )
Functions ¶
This section is empty.
Types ¶
type DefaultRateLimiter ¶
type DefaultRateLimiter struct {
// contains filtered or unexported fields
}
DefaultRateLimiter struct
func NewDefaultRateLimiter ¶
func NewDefaultRateLimiter(redisClient *redis.Client, limit int, period time.Duration) (*DefaultRateLimiter, error)
NewDefaultRateLimiter creates a new rate limiter
func (*DefaultRateLimiter) GetKey ¶ added in v0.6.1
func (d *DefaultRateLimiter) GetKey(ip string) string
GetKey gets the rate limiter key
func (*DefaultRateLimiter) Limit ¶
func (d *DefaultRateLimiter) Limit(ip string) error
Limit limits the rate of requests
func (*DefaultRateLimiter) SetInitialValue ¶ added in v0.6.1
func (d *DefaultRateLimiter) SetInitialValue(key string) error
SetInitialValue sets the initial value for the given key
Click to show internal directories.
Click to hide internal directories.