Browse Source
Add rate limiting requests per minute field to settings
feature/update-route-registration
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
6 deletions
-
main.go
-
settings/settings.go
-
settings/settings_test.go
|
@ -61,7 +61,7 @@ func main() { |
|
|
pipes := pipelines.LoadPipelines() |
|
|
pipes := pipelines.LoadPipelines() |
|
|
|
|
|
|
|
|
authMiddleware := middlewares.CreateAuthenticationMiddleware(appSettings.Token) |
|
|
authMiddleware := middlewares.CreateAuthenticationMiddleware(appSettings.Token) |
|
|
rateLimiterMiddleware, err := middlewares.CreateRateLimiterMiddleware(2) |
|
|
|
|
|
|
|
|
rateLimiterMiddleware, err := middlewares.CreateRateLimiterMiddleware(appSettings.RequestsPerMinute) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
panic(err) |
|
|
panic(err) |
|
|
} |
|
|
} |
|
|
|
@ -15,9 +15,10 @@ const ( |
|
|
type FileSystemType int |
|
|
type FileSystemType int |
|
|
|
|
|
|
|
|
type Settings struct { |
|
|
type Settings struct { |
|
|
Endpoint string `json:"endpoint"` |
|
|
|
|
|
Token string `json:"token"` |
|
|
|
|
|
StorageProvider StorageSettings `json:"storage_provider"` |
|
|
|
|
|
|
|
|
Endpoint string `json:"endpoint"` |
|
|
|
|
|
Token string `json:"token"` |
|
|
|
|
|
RequestsPerMinute int `json:"requests_per_minute"` |
|
|
|
|
|
StorageProvider StorageSettings `json:"storage_provider"` |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
type StorageSettings struct { |
|
|
type StorageSettings struct { |
|
@ -49,8 +50,9 @@ func LoadSettings(fileSystem afero.Fs) (Settings, error) { |
|
|
|
|
|
|
|
|
// If file does not exist, create default settings
|
|
|
// If file does not exist, create default settings
|
|
|
defaultSettings := Settings{ |
|
|
defaultSettings := Settings{ |
|
|
Endpoint: "127.0.0.1:8000", |
|
|
|
|
|
Token: "changeme", |
|
|
|
|
|
|
|
|
Endpoint: "127.0.0.1:8000", |
|
|
|
|
|
Token: "changeme", |
|
|
|
|
|
RequestsPerMinute: 20, |
|
|
StorageProvider: StorageSettings{ |
|
|
StorageProvider: StorageSettings{ |
|
|
Type: Local, |
|
|
Type: Local, |
|
|
BasePath: "assets", |
|
|
BasePath: "assets", |
|
|
|
@ -13,6 +13,7 @@ func TestSettingsParsing(t *testing.T) { |
|
|
const file string = `{ |
|
|
const file string = `{ |
|
|
"endpoint": "0.0.0.0:8000", |
|
|
"endpoint": "0.0.0.0:8000", |
|
|
"token": "foobar", |
|
|
"token": "foobar", |
|
|
|
|
|
"requests_per_minute": 20, |
|
|
"storage_provider": { |
|
|
"storage_provider": { |
|
|
"type": 0, |
|
|
"type": 0, |
|
|
"base_path": "assets" |
|
|
"base_path": "assets" |
|
|