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.