1
0
mirror of https://github.com/pocket-id/pocket-id.git synced 2026-02-04 12:46:45 +00:00

feat: add environment variable to disable built-in rate limiting

This commit is contained in:
Elias Schneider
2026-01-11 12:34:26 +01:00
parent d318b02ea0
commit 0d40d30d87
2 changed files with 11 additions and 4 deletions

View File

@@ -74,6 +74,7 @@ type EnvConfigSchema struct {
MetricsEnabled bool `env:"METRICS_ENABLED"` MetricsEnabled bool `env:"METRICS_ENABLED"`
TracingEnabled bool `env:"TRACING_ENABLED"` TracingEnabled bool `env:"TRACING_ENABLED"`
LogJSON bool `env:"LOG_JSON"` LogJSON bool `env:"LOG_JSON"`
DisableRateLimiting bool `env:"DISABLE_RATE_LIMITING"`
} }
var EnvConfig = defaultConfig() var EnvConfig = defaultConfig()

View File

@@ -17,6 +17,12 @@ func NewRateLimitMiddleware() *RateLimitMiddleware {
} }
func (m *RateLimitMiddleware) Add(limit rate.Limit, burst int) gin.HandlerFunc { func (m *RateLimitMiddleware) Add(limit rate.Limit, burst int) gin.HandlerFunc {
if common.EnvConfig.DisableRateLimiting == true {
return func(c *gin.Context) {
c.Next()
}
}
// Map to store the rate limiters per IP // Map to store the rate limiters per IP
var clients = make(map[string]*client) var clients = make(map[string]*client)
var mu sync.Mutex var mu sync.Mutex