photoprism/internal/server/limiter/middleware.go
Michael Mayer fed1d8ad95 Auth: Accept access token as passwd with fail rate limit #782 #808 #3943
Signed-off-by: Michael Mayer <michael@photoprism.app>
2024-01-14 18:28:17 +01:00

17 lines
324 B
Go

package limiter
import (
"net/http"
"github.com/gin-gonic/gin"
)
// Middleware registers the IP rate limiter middleware.
func Middleware(limiter *Limit) gin.HandlerFunc {
return func(c *gin.Context) {
if l := limiter.IP(c.ClientIP()); !l.Allow() {
c.AbortWithStatus(http.StatusTooManyRequests)
return
}
}
}