summaryrefslogtreecommitdiffci
path: root/internal/router/router.go
diff options
from:
to:
context:
space:
mode:
authorGravatar SayaAndy <saya.andy@posteo.com> 2026-05-02 14:29:55 +0700
committerGravatar SayaAndy <saya.andy@posteo.com> 2026-05-02 14:29:55 +0700
commitca1f36376865cb2a20923aa62fdff3ee217abde3 (patch)
tree2e3676489327505dd2b4d53023ca0da6fc2dc5a2 /internal/router/router.go
parent3898baa47faf268864ecac3699f7e98c6cac01a4 (diff)
downloadweb-ca1f36376865cb2a20923aa62fdff3ee217abde3.tar.gz
web-ca1f36376865cb2a20923aa62fdff3ee217abde3.zip
feat: implement rate limiting
Diffstat (limited to 'internal/router/router.go')
-rw-r--r--internal/router/router.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/internal/router/router.go b/internal/router/router.go
index 926d21a..5230e74 100644
--- a/internal/router/router.go
+++ b/internal/router/router.go
@@ -78,6 +78,7 @@ type Route interface {
TemplatesToInject() []string
SitemapInfo(supplements *Supplements) []SitemapInfo
ContentType() string
+ RateLimiter() *fiber.Handler
Render(c *fiber.Ctx, supplements *Supplements, lang string, templateMap fiber.Map) (statusCode int, err error)
AddMeta(c *fiber.Ctx, supplements *Supplements, lang string, templateMap fiber.Map) (meta []MetaField, err error)
AddLinkedData(c *fiber.Ctx, supplements *Supplements, lang string, templateMap fiber.Map) (ld map[string]any, err error)
@@ -267,6 +268,10 @@ func (r *Router) InitRoutes() (err error) {
return fmt.Errorf("failed to add '%s %s' route into template manager: %w", method, match, err)
}
+ if rateLimiter := route.RateLimiter(); rateLimiter != nil {
+ r.app.Use(match, *rateLimiter)
+ }
+
if route.IsTemplated() {
if _, ok := r.templatedRoutes[method]; !ok {
r.templatedRoutes[method] = make(map[string]Route)