From db76499c138501f03d6c1a8be8c9c81e652a8769 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Thu, 15 Jul 2021 20:00:44 +0700 Subject: [PATCH] chore: bump limiter --- api/main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/api/main.go b/api/main.go index 26ce84b..8cdc9f7 100644 --- a/api/main.go +++ b/api/main.go @@ -44,7 +44,11 @@ func main() { ErrorHandler: errorHandler, }) 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.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. func StartServerWithGracefulShutdown(a *fiber.App) { // Create channel for idle connections.