photoprism/internal/server/limiter/middleware.go
Michael Mayer 6abbc39017 Security: Add http rate limiter and auto tls mode #98
Signed-off-by: Michael Mayer <michael@photoprism.app>
2022-10-11 22:44:11 +02:00

17 lines
314 B
Go

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