chore: bump limiter

This commit is contained in:
Reinaldy Rafli 2021-07-15 20:00:44 +07:00
parent 02e9289058
commit db76499c13
1 changed files with 11 additions and 1 deletions

View File

@ -44,7 +44,11 @@ func main() {
ErrorHandler: errorHandler, ErrorHandler: errorHandler,
}) })
app.Use(cors.New()) app.Use(cors.New())
app.Use(limiter.New()) app.Use(limiter.New(limiter.Config{
Max: 15,
Duration: 1 * time.Minute,
LimitReached: limitHandler,
}))
app.Use(etag.New()) app.Use(etag.New())
app.Mount("/v1", v1.New()) app.Mount("/v1", v1.New())
@ -65,6 +69,12 @@ func errorHandler(c *fiber.Ctx, err error) error {
}) })
} }
func limitHandler(c *fiber.Ctx) error {
return c.Status(fiber.StatusTooManyRequests).JSON(fiber.Map{
"message": "we only allow up to 15 request per minute",
})
}
// StartServerWithGracefulShutdown function for starting server with a graceful shutdown. // StartServerWithGracefulShutdown function for starting server with a graceful shutdown.
func StartServerWithGracefulShutdown(a *fiber.App) { func StartServerWithGracefulShutdown(a *fiber.App) {
// Create channel for idle connections. // Create channel for idle connections.