Skip to content

Commit

Permalink
no redis counter if redis disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
klaidliadon committed Feb 26, 2024
1 parent dac8a3d commit fc8529d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type Config struct {
}

func (cfg Config) RedisRateLimitConfig() *httprateredis.Config {
if !cfg.Redis.Enabled {
return nil

}
return &httprateredis.Config{
Host: cfg.Redis.Host,
Port: cfg.Redis.Port,
Expand Down
5 changes: 4 additions & 1 deletion ratelimiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ func NewHTTPRateLimiter(cfg Config, vary RateLimitVaryFn) func(next http.Handler
// httprate limit counter
const _DefaultRPM = 120

limitCounter, _ := httprateredis.NewRedisLimitCounter(cfg.RedisRateLimitConfig())
var limitCounter httprate.LimitCounter
if redisCfg := cfg.RedisRateLimitConfig(); redisCfg != nil {
limitCounter, _ = httprateredis.NewRedisLimitCounter(redisCfg)
}

limitErr := proto.ErrLimitExceeded
if cfg.RateLimiter.ErrorMessage != "" {
Expand Down

0 comments on commit fc8529d

Please sign in to comment.