Documentation ¶
Index ¶
- func GetIPAddress(c *gin.Context) (string, error)
- func IPLimiter(limiter RateLimiter) gin.HandlerFunc
- func IPUserLimiter(limiter RateLimiter, user_id string) gin.HandlerFunc
- func UserLimiter(limiter RateLimiter, user_id string) gin.HandlerFunc
- type RateLimiter
- func (limiter *RateLimiter) AllowConsecutiveRequest(user_params ...string) bool
- func (limiter *RateLimiter) AllowRequest(user_params ...string) bool
- func (limiter *RateLimiter) AllowWithinTotalRequests(user_params ...string) bool
- func (limiter *RateLimiter) UpdateConsecutiveRequests(user_params ...string)
- func (limiter *RateLimiter) UpdateRequest(user_params ...string)
- func (limiter *RateLimiter) UpdateTotalRequests(user_params ...string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IPLimiter ¶
func IPLimiter(limiter RateLimiter) gin.HandlerFunc
enforce rate limit based on ip address of client making the request
func IPUserLimiter ¶
func IPUserLimiter(limiter RateLimiter, user_id string) gin.HandlerFunc
enforce rate limit based on ip address of client and user making the request
func UserLimiter ¶
func UserLimiter(limiter RateLimiter, user_id string) gin.HandlerFunc
enforce rate limit based on the user making the request
Types ¶
type RateLimiter ¶
type RateLimiter struct { TotalLimit int // maximum allowed requests over all BurstLimit int // maximum allowed consecutive requests in a short burst MaxTime time.Duration // period for maximum allowed requests BurstPeriod time.Duration // period for short bursts Client *redis.Client TotalLimitPrefix string // prefix for total limit key in memory cache BurstLimitPrefix string // prefix for bursts limit key in memory cache }
RateLimiter is the limiter instance
func (*RateLimiter) AllowConsecutiveRequest ¶
func (limiter *RateLimiter) AllowConsecutiveRequest(user_params ...string) bool
check if consecutive requests made within specified limit before accepting new user request
func (*RateLimiter) AllowRequest ¶
func (limiter *RateLimiter) AllowRequest(user_params ...string) bool
check if consecutive and total requests made within specified limit before accepting new user request
func (*RateLimiter) AllowWithinTotalRequests ¶
func (limiter *RateLimiter) AllowWithinTotalRequests(user_params ...string) bool
check if total requests made within specified limit before accepting new user request
func (*RateLimiter) UpdateConsecutiveRequests ¶
func (limiter *RateLimiter) UpdateConsecutiveRequests(user_params ...string)
note consecutive requests in short bursts made with user parameters and update per new request made
func (*RateLimiter) UpdateRequest ¶
func (limiter *RateLimiter) UpdateRequest(user_params ...string)
note consecutive and total requests in made with user parameters and update each as per new request made
func (*RateLimiter) UpdateTotalRequests ¶
func (limiter *RateLimiter) UpdateTotalRequests(user_params ...string)
note total requests made with user parameters and update per new request made