Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RateLimitConfig ¶
type RateLimitConfig struct { MaxRequests int // Maximum number of requests allowed in a given interval. Interval time.Duration // The interval in which MaxRequests are counted. }
RateLimitConfig struct holds the configuration for rate limiting.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter struct holds the configurations and states for the rate limiter.
func NewRateLimiter ¶
func NewRateLimiter(rdb *redis.Client, defaultConf RateLimitConfig) *RateLimiter
NewRateLimiter function initializes and returns a new RateLimiter instance. It accepts a Redis client and a default rate limiting configuration.
func (*RateLimiter) AddCustomRateLimit ¶
func (rl *RateLimiter) AddCustomRateLimit(endpoint string, conf RateLimitConfig)
AddCustomRateLimit function adds a custom rate limiting configuration for a specific endpoint. It is thread-safe and can be called concurrently.
func (*RateLimiter) Allow ¶
func (rl *RateLimiter) Allow(ctx context.Context, userId, endpoint string) bool
Allow function checks if a request from a user to a specific endpoint should be allowed or denied based on the rate limiting rules. It is not fully thread-safe as of this implementation and should not be called concurrently without consideration.