From 2195181ce5e24634802d87e5988ab65d28987a7d Mon Sep 17 00:00:00 2001 From: TungHoang Date: Sun, 7 May 2023 16:42:01 +0200 Subject: [PATCH] Add configs for rate limit --- pkg/config/config.go | 7 ++++--- plugins/rate_limit.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index 245b781c5..a855f75dd 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -91,9 +91,10 @@ type SslOptions struct { // declare RateLimitConfig type RateLimitOptions struct { - RequestsPerSecond int - BurstSize int - CleanupInterval config.Duration + Enabled bool `json:"enabled"` + RequestsPerSecond int `json:"requestsPerSecond"` + BurstSize int `json:"burstSize"` + CleanupInterval config.Duration `json:"cleanupInterval"` } var defaultServerConfig = &ServerConfig{ diff --git a/plugins/rate_limit.go b/plugins/rate_limit.go index 283461cd8..0197c0cf3 100644 --- a/plugins/rate_limit.go +++ b/plugins/rate_limit.go @@ -27,7 +27,7 @@ type Limiter struct { // define a function named Allow that takes userID and returns RateLimitError // the function check if the user is in the map, if not, create a new accessRecords for the user // then it check if the user can access the resource, if not, return RateLimitError -func (l *Limiter) Allow(userID string) RateLimitError { +func (l *Limiter) Allow(userID string) error { l.mutex.Lock() defer l.mutex.Unlock() if _, ok := l.accessPerUser[userID]; !ok {