Browse Source
Add enabled field to rate limiter settings
feature/make-middlewares-optional
Fabian Vowie
3 years ago
No known key found for this signature in database
GPG Key ID: C27317C33B27C410
3 changed files with
9 additions and
3 deletions
-
main.go
-
settings/settings.go
-
settings/settings_test.go
|
@ -71,7 +71,10 @@ func main() { |
|
|
|
|
|
|
|
|
r := mux.NewRouter() |
|
|
r := mux.NewRouter() |
|
|
r.Use(authMiddleware.Middleware) |
|
|
r.Use(authMiddleware.Middleware) |
|
|
|
|
|
|
|
|
|
|
|
if appSettings.RateLimiter.Enabled { |
|
|
r.Use(rateLimiterMiddleware.Middleware) |
|
|
r.Use(rateLimiterMiddleware.Middleware) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
r.HandleFunc("/", IndexHandler) |
|
|
r.HandleFunc("/", IndexHandler) |
|
|
|
|
|
|
|
|
|
@ -27,6 +27,7 @@ type StorageSettings struct { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type RateLimiterSettings struct { |
|
|
type RateLimiterSettings struct { |
|
|
|
|
|
Enabled bool `json:"enabled"` |
|
|
RequestsPerMinute int `json:"requests_per_minute"` |
|
|
RequestsPerMinute int `json:"requests_per_minute"` |
|
|
AllowedBurst int `json:"allowed_burst"` |
|
|
AllowedBurst int `json:"allowed_burst"` |
|
|
} |
|
|
} |
|
@ -58,6 +59,7 @@ func LoadSettings(fileSystem afero.Fs) (Settings, error) { |
|
|
Endpoint: "127.0.0.1:8000", |
|
|
Endpoint: "127.0.0.1:8000", |
|
|
Token: "changeme", |
|
|
Token: "changeme", |
|
|
RateLimiter: RateLimiterSettings{ |
|
|
RateLimiter: RateLimiterSettings{ |
|
|
|
|
|
Enabled: true, |
|
|
RequestsPerMinute: 20, |
|
|
RequestsPerMinute: 20, |
|
|
AllowedBurst: 5, |
|
|
AllowedBurst: 5, |
|
|
}, |
|
|
}, |
|
|
|
@ -14,6 +14,7 @@ func TestSettingsParsing(t *testing.T) { |
|
|
"endpoint": "0.0.0.0:8000", |
|
|
"endpoint": "0.0.0.0:8000", |
|
|
"token": "foobar", |
|
|
"token": "foobar", |
|
|
"rate_limiter": { |
|
|
"rate_limiter": { |
|
|
|
|
|
"enabled": true, |
|
|
"requests_per_minute": 20, |
|
|
"requests_per_minute": 20, |
|
|
"allowed_burst": 5 |
|
|
"allowed_burst": 5 |
|
|
}, |
|
|
}, |
|
|