From a94edd70d5573f3af6823f477921214e6e36ca05 Mon Sep 17 00:00:00 2001 From: Yanislav Igonin Date: Wed, 6 Apr 2022 10:59:05 +0300 Subject: [PATCH] add rate limiter --- main.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 5be8a78..36ee373 100644 --- a/main.go +++ b/main.go @@ -2,17 +2,20 @@ package main import ( "log" + "strconv" + + _ "github.com/joho/godotenv/autoload" + + "github.com/gofiber/fiber/v2" + "github.com/gofiber/fiber/v2/middleware/limiter" + "github.com/gofiber/template/html" + "micrach/build" "micrach/config" "micrach/db" "micrach/repositories" "micrach/templates" "micrach/utils" - "strconv" - - "github.com/gofiber/fiber/v2" - "github.com/gofiber/template/html" - _ "github.com/joho/godotenv/autoload" ) // import ( @@ -120,6 +123,11 @@ func main() { app := fiber.New(fiber.Config{ Views: engine, }) + app.Use(limiter.New(limiter.Config{ + Next: func(c *fiber.Ctx) bool { + return c.IP() == "127.0.0.1" + }, + })) app.Static("/uploads", "./uploads") app.Static("/static", "./static")