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:
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user