mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 10:18:59 +02:00
remove api ratelimiter
This commit is contained in:
@@ -8,8 +8,6 @@ import (
|
|||||||
"github.com/yusing/go-proxy/internal/api/v1/auth"
|
"github.com/yusing/go-proxy/internal/api/v1/auth"
|
||||||
. "github.com/yusing/go-proxy/internal/api/v1/utils"
|
. "github.com/yusing/go-proxy/internal/api/v1/utils"
|
||||||
"github.com/yusing/go-proxy/internal/common"
|
"github.com/yusing/go-proxy/internal/common"
|
||||||
"github.com/yusing/go-proxy/internal/logging"
|
|
||||||
"github.com/yusing/go-proxy/internal/net/http/middleware"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type ServeMux struct{ *http.ServeMux }
|
type ServeMux struct{ *http.ServeMux }
|
||||||
@@ -19,7 +17,7 @@ func NewServeMux() ServeMux {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (mux ServeMux) HandleFunc(method, endpoint string, handler http.HandlerFunc) {
|
func (mux ServeMux) HandleFunc(method, endpoint string, handler http.HandlerFunc) {
|
||||||
mux.ServeMux.HandleFunc(method+" "+endpoint, checkHost(rateLimited(handler)))
|
mux.ServeMux.HandleFunc(method+" "+endpoint, checkHost(handler))
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHandler() http.Handler {
|
func NewHandler() http.Handler {
|
||||||
@@ -58,16 +56,3 @@ func checkHost(f http.HandlerFunc) http.HandlerFunc {
|
|||||||
f(w, r)
|
f(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func rateLimited(f http.HandlerFunc) http.HandlerFunc {
|
|
||||||
m, err := middleware.RateLimiter.New(middleware.OptionsRaw{
|
|
||||||
"average": 10,
|
|
||||||
"burst": 10,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
logging.Fatal().Err(err).Msg("unable to create API rate limiter")
|
|
||||||
}
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
m.ModifyRequest(f, w, r)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user