goshorly/utils/limiter.go
Phil 802b93bdaf
Some checks failed
ci/woodpecker/push/99-release-bot Pipeline was successful
ci/woodpecker/push/1-build-check unknown status
ci/woodpecker/push/10-build-dev unknown status
ci/woodpecker/push/0-pre Pipeline failed
[CI Workflow] Improvments for next releses and logic (#11)
- [X] Changed latest / dev builds (security)
- [x]  Changed logic behind build and tags (breaking)
- [x]  Make more checks and buildflags (feature)
- [x]  New releases for @renovate-bot (enhancement)

Reviewed-on: #11
2025-04-07 17:41:41 +00:00

27 lines
734 B
Go

package utils
import (
"time"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/limiter"
)
var ConfigLimiter limiter.Config = limiter.Config{
Max: 10,
Expiration: 60 * time.Second,
LimitReached: func(c *fiber.Ctx) error {
if c.Get("content-type") == "application/json" {
return c.Status(418).JSON(fiber.Map{
"msg": "Too many requests, slow down I'm a teapot (10 requests per minute)",
"success": false,
})
}
return c.Render("views/home", fiber.Map{
"ERR": "You have reached the limit of requests! Please check back later. (1 minute)",
"CI_COMMIT_SHA": CI_COMMIT_SHA,
"CI_COMMIT_BRANCH": CI_COMMIT_BRANCH,
"CI_BUILD": CI_BUILD,
})
},
}