aboutsummaryrefslogtreecommitdiff
path: root/backend/api/rate.go
blob: 1e262af1e4efd4f0ae477dadb3267d1e98143fef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package api

import (
	"net/http"

	"golang.org/x/time/rate"

	"github.com/gin-gonic/gin"
)

func RateLimit(c *gin.Context) {
	limiter := rate.NewLimiter(1, 5) // don't know if this is too much or not enough tbh
	if limiter.Allow() {
		c.Next()
	} else {
		c.AbortWithStatusJSON(http.StatusTooManyRequests, gin.H{
			"error": "Rate limit exceeded",
		})
	}
}