We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e4006e9 commit 4561d4dCopy full SHA for 4561d4d
internal/users/transport/middlewares.go
@@ -10,6 +10,8 @@ import (
10
"net/http"
11
"strings"
12
13
+ "golang.org/x/time/rate"
14
+
15
"github.com/Edmartt/go-authentication-api/internal/users/models"
16
"github.com/Edmartt/go-authentication-api/pkg/jwt"
17
)
@@ -89,3 +91,17 @@ func IsAuthorized(handler http.HandlerFunc) http.HandlerFunc{
89
91
handler(w, r.WithContext(ctx))
90
92
}
93
94
95
96
97
+func LimitRequest(next http.Handler) http.Handler{
98
+ limit := rate.NewLimiter(0.3, 3)
99
100
+ return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
101
+ if limit.Allow() == false{
102
+ http.Error(w, http.StatusText(429), http.StatusTooManyRequests)
103
+ return
104
+ }
105
+ next.ServeHTTP(w, r)
106
+ })
107
+}
0 commit comments