feat: add configurable test mode and rate limiting
- Add TestMode, RateLimitEnabled, RequestsPerMinute to Config - Add getEnvBool() and getEnvInt() helper functions - Update rate limiter to support enabled/disabled state - Pass test environment variables through docker-compose - Configure rate limiter dynamically in main.go This allows disabling rate limiting for integration testing while maintaining security in production environments.
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
// RateLimiterConfig defines rate limiting configuration
|
||||
type RateLimiterConfig struct {
|
||||
Enabled bool
|
||||
RequestsPerMinute int
|
||||
CleanupInterval time.Duration
|
||||
}
|
||||
@@ -17,6 +18,7 @@ type RateLimiterConfig struct {
|
||||
// DefaultRateLimiterConfig returns sensible defaults
|
||||
func DefaultRateLimiterConfig() RateLimiterConfig {
|
||||
return RateLimiterConfig{
|
||||
Enabled: true,
|
||||
RequestsPerMinute: 10,
|
||||
CleanupInterval: 5 * time.Minute,
|
||||
}
|
||||
@@ -98,6 +100,11 @@ func (rl *RateLimiter) Allow(ip string) bool {
|
||||
func RateLimiterMiddleware(rl *RateLimiter) echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
// If rate limiting is disabled, skip checks
|
||||
if !rl.config.Enabled {
|
||||
return next(c)
|
||||
}
|
||||
|
||||
// Get client IP
|
||||
ip := c.RealIP()
|
||||
if ip == "" {
|
||||
|
||||
Reference in New Issue
Block a user