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:
2026-01-29 13:33:18 -05:00
parent ce0e448e58
commit 4b8cb58c84
4 changed files with 59 additions and 17 deletions
+7
View File
@@ -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 == "" {