feat: add middlewares config for rest (#2765)

* feat: add middlewares config for rest

* chore: disable logs in tests

* chore: enable verbose in tests
This commit is contained in:
Kevin Wan
2023-01-08 16:41:53 +08:00
committed by GitHub
parent f4502171ea
commit ade6f9ee46
5 changed files with 67 additions and 17 deletions

View File

@@ -8,8 +8,8 @@ import (
"github.com/zeromicro/go-zero/rest/internal"
)
// MaxConns returns a middleware that limit the concurrent connections.
func MaxConns(n int) func(http.Handler) http.Handler {
// MaxConnsHandler returns a middleware that limit the concurrent connections.
func MaxConnsHandler(n int) func(http.Handler) http.Handler {
if n <= 0 {
return func(next http.Handler) http.Handler {
return next

View File

@@ -24,7 +24,7 @@ func TestMaxConnsHandler(t *testing.T) {
done := make(chan lang.PlaceholderType)
defer close(done)
maxConns := MaxConns(conns)
maxConns := MaxConnsHandler(conns)
handler := maxConns(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
waitGroup.Done()
<-done
@@ -54,7 +54,7 @@ func TestWithoutMaxConnsHandler(t *testing.T) {
done := make(chan lang.PlaceholderType)
defer close(done)
maxConns := MaxConns(0)
maxConns := MaxConnsHandler(0)
handler := maxConns(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
val := r.Header.Get(key)
if val == value {