diff --git a/main.go b/main.go index 030aa5b..3d2f59d 100644 --- a/main.go +++ b/main.go @@ -71,7 +71,10 @@ func main() { r := mux.NewRouter() r.Use(authMiddleware.Middleware) - r.Use(rateLimiterMiddleware.Middleware) + + if appSettings.RateLimiter.Enabled { + r.Use(rateLimiterMiddleware.Middleware) + } r.HandleFunc("/", IndexHandler) diff --git a/settings/settings.go b/settings/settings.go index 6e33efe..8b0264d 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -27,8 +27,9 @@ type StorageSettings struct { } type RateLimiterSettings struct { - RequestsPerMinute int `json:"requests_per_minute"` - AllowedBurst int `json:"allowed_burst"` + Enabled bool `json:"enabled"` + RequestsPerMinute int `json:"requests_per_minute"` + AllowedBurst int `json:"allowed_burst"` } func parseSettings(data []byte) Settings { @@ -58,6 +59,7 @@ func LoadSettings(fileSystem afero.Fs) (Settings, error) { Endpoint: "127.0.0.1:8000", Token: "changeme", RateLimiter: RateLimiterSettings{ + Enabled: true, RequestsPerMinute: 20, AllowedBurst: 5, }, diff --git a/settings/settings_test.go b/settings/settings_test.go index fa801ff..8f91392 100644 --- a/settings/settings_test.go +++ b/settings/settings_test.go @@ -14,6 +14,7 @@ func TestSettingsParsing(t *testing.T) { "endpoint": "0.0.0.0:8000", "token": "foobar", "rate_limiter": { + "enabled": true, "requests_per_minute": 20, "allowed_burst": 5 },