Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidKeyPrefix = errors.New("invalid key prefix")
ErrInvalidKeyPrefix signals that an invalid key prefix has been provided
var ErrKeyNotExists = errors.New("key does not exist")
ErrKeyNotExists signals that key does not exist
var ErrNilRedisClient = errors.New("nil redis client")
ErrNilRedisClient signals that a nil redis client has been provided
var ErrNilRedisClientWrapper = errors.New("nil redis client wrapper")
ErrNilRedisClientWrapper signals that a nil redis client component has been provided
var ErrNoExpirationTimeForKey = errors.New("key has no expiration time")
ErrNoExpirationTimeForKey signals that key has no expiration time
var ErrRedisConnectionFailed = errors.New("error connecting to redis")
ErrRedisConnectionFailed signals that connection to redis failed
Functions ¶
func NewRateLimiter ¶
func NewRateLimiter(args ArgsRateLimiter) (*rateLimiter, error)
NewRateLimiter will create a new instance of rate limiter
func NewRedisClientWrapper ¶
func NewRedisClientWrapper(client redis.UniversalClient) (*redisClientWrapper, error)
NewRedisClientWrapper will create a new redis client wrapper component
Types ¶
type ArgsRateLimiter ¶
type ArgsRateLimiter struct { OperationTimeoutInSec uint64 FreezeFailureConfig FailureConfig SecurityModeFailureConfig FailureConfig Storer RedisStorer }
ArgsRateLimiter defines the arguments needed for creating a rate limiter component
type FailureConfig ¶ added in v1.0.14
FailureConfig defines the configuration for the rate limiter failure configuration
type RateLimiter ¶
type RateLimiter interface { CheckAllowedAndIncreaseTrials(key string, mode Mode) (*RateLimiterResult, error) Reset(key string) error DecrementSecurityFailedTrials(key string) error Period(mode Mode) time.Duration Rate(mode Mode) int IsInterfaceNil() bool }
RateLimiter defines the behaviour of a rate limiter component
func CreateRedisRateLimiter ¶
func CreateRedisRateLimiter(cfg config.RedisConfig, twoFactorCfg config.TwoFactorConfig) (RateLimiter, error)
CreateRedisRateLimiter will create a new redis rate limiter component
type RateLimiterResult ¶
type RateLimiterResult struct { // Allowed specifies if the request was allowed, 1 if allowed // and 0 if not allowed Allowed bool // Remaining is the maximum number of requests that could be // permitted instantaneously for this key given the current // state. For example, if a rate limiter allows 10 requests per // second and has already received 6 requests for this key this // second, Remaining would be 4. Remaining int // ResetAfter is the time until the expiration time is reached // for a given key. For example, if a rate limiter // manages requests per minute and received one request 20s ago, // reset after would return 40s ResetAfter time.Duration }
RateLimiterResult defines rate limiter result
type RedisStorer ¶
type RedisStorer interface { Increment(ctx context.Context, key string) (int64, error) Decrement(ctx context.Context, key string) (int64, error) SetExpire(ctx context.Context, key string, ttl time.Duration) (bool, error) SetExpireIfNotExists(ctx context.Context, key string, ttl time.Duration) (bool, error) ResetCounterAndKeepTTL(ctx context.Context, key string) error ExpireTime(ctx context.Context, key string) (time.Duration, error) IsConnected(ctx context.Context) bool IsInterfaceNil() bool }
RedisStorer defines the behaviour of a redis storer component