-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* implement in memory rate limiter * make it configurable * make it configurable * shuttles
- Loading branch information
Showing
6 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package util | ||
|
||
import ( | ||
"github.com/labstack/echo/v4" | ||
"github.com/labstack/echo/v4/middleware" | ||
"golang.org/x/time/rate" | ||
) | ||
|
||
func ConfigureRateLimiter(rateLimit rate.Limit) middleware.RateLimiterConfig { | ||
config := middleware.DefaultRateLimiterConfig | ||
|
||
config.IdentifierExtractor = func(ctx echo.Context) (string, error) { | ||
var id string | ||
user, ok := ctx.Get("user").(User) | ||
if !ok { | ||
id = ctx.RealIP() | ||
} else { | ||
id = user.UUID | ||
} | ||
return id, nil | ||
} | ||
|
||
config.Store = middleware.NewRateLimiterMemoryStore(rateLimit) | ||
|
||
return config | ||
} |