Documentation
¶
Overview ¶
Package ratelimiter provides possibility to check rate limit usage by given resource with given allowed rate and time interval. It uses redis as backend so can be used to check ratelimit for distributed instances of your app.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LimitCtx ¶
type LimitCtx struct { // ported from here: http://flask.pocoo.org/snippets/70/ ExpireAt int64 Key string Limit int Per time.Duration Current int Tries int RedisPool *redis.Pool }
func BuildLimiter ¶
func BuildLimiter(redisPool *redis.Pool, key string, limit int, per time.Duration, tries int) *LimitCtx
Initializes new LimiterCtx instance which then can be used to increment and check ratelimit usage
func Incr ¶
func Incr(redisPool *redis.Pool, name string, limit int, period time.Duration, retries int) (*LimitCtx, error)
Shorthand function to increment resource usage and to get LimiterCtx back. Wrapper around BuildLimiter and LimiterCtx.Incr
Click to show internal directories.
Click to hide internal directories.