Documentation ¶
Index ¶
Constants ¶
const IdleTimeout = 240 * time.Second
const LimitInterval = 3600 * time.Second
const MaxIdle = 40
const MaxQuota = 5000
module constants
const MilliSecond = int64(time.Millisecond)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
`Bucket` defines the model for `Quota`, `Used` & `Remaining`
type Limit ¶
`Limit` struct defines the model of `Limiter`. essential fields include:
- `Quota`
- `Used`
- `Remaining`
- `RetryAfter` epoch timestamp
type RedisLimiter ¶
type RedisLimiter struct { Pool *redis.Pool PrefixQuota string PrefixRemaining string PrefixReset string Duration time.Duration Quota int }
`RedisLimiter` Limits connections based on a max quota that they (`end_user_of_api`) are entitled to, and the quota that they have already consumed. Useful for Web Applications, to avoid abuse of APIs etc, by limiting everyone to a max quota of ex: 5000 requests per hour per `identifier`. The `identifier` has to be choosen by the `user` cosuming `RedisLimiter`
func Init ¶
func Init(address net.Addr) (*RedisLimiter, error)
Init returns a new RedisLimiter. Options:
- `address` net.Addr
@return *RedisLimiter, error
func (*RedisLimiter) Close ¶
func (s *RedisLimiter) Close() error
Close closes the underlying *redis.Pool
type RetryAfter ¶
type RetryAfter struct {
// contains filtered or unexported fields
}
`RetryAfter` defines for `self`