Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Add configs for rate limit
Browse files Browse the repository at this point in the history
Signed-off-by: TungHoang <[email protected]>
  • Loading branch information
LaPetiteSouris committed May 8, 2023
1 parent 39019f5 commit 80214ce
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion plugins/rate_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 80214ce

Please sign in to comment.