Skip to content

Commit

Permalink
Update xhttp middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed May 22, 2024
1 parent 8150de3 commit f6a7390
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/xhttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ go get github.com/mix-go/xhttp
| xhttp.WithTimeout(timeout time.Duration) RequestOption | Set configuration item. |
| xhttp.WithDebugFunc(f DebugFunc) RequestOption | Set configuration item. |
| xhttp.WithRetry(f RetryIfFunc, opts ...retry.Option) RequestOption | Set configuration item. |
| xhttp.WithMiddlewares(middlewares ...Middleware) RequestOption | Set configuration item. |
| xhttp.WithMiddleware(middlewares ...Middleware) RequestOption | Set configuration item. |
| xhttp.BuildJSON(v interface{}) Body | Generate json string. |
| xhttp.BuildQuery(m map[string]string) Body | Generate urlencoded query string. |
| xhttp.Shutdown(ctx context.Context) | Do shutdown. |
Expand Down Expand Up @@ -112,7 +112,7 @@ logicMiddleware := func(next xhttp.HandlerFunc) xhttp.HandlerFunc {
return resp, err
}
}
resp, err := xhttp.NewRequest("GET", "https://github.com/", xhttp.WithMiddlewares(logicMiddleware))
resp, err := xhttp.NewRequest("GET", "https://github.com/", xhttp.WithMiddleware(logicMiddleware))
```

## Shutdown
Expand Down
6 changes: 3 additions & 3 deletions src/xhttp/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func TestMiddlewares(t *testing.T) {
return resp, err
}
}
resp, err := xhttp.NewRequest("GET", "https://github.com/", xhttp.WithMiddlewares(logicMiddleware))
resp, err := xhttp.NewRequest("GET", "https://github.com/", xhttp.WithMiddleware(logicMiddleware))

a.Equal(resp.StatusCode, 200)
a.Nil(err)
Expand All @@ -160,14 +160,14 @@ func TestShutdown(t *testing.T) {
return resp, err
}
}
_, err := xhttp.NewRequest("GET", "https://github.com/", xhttp.WithMiddlewares(logicMiddleware))
_, err := xhttp.NewRequest("GET", "https://github.com/", xhttp.WithMiddleware(logicMiddleware))
a.Nil(err)
wg := sync.WaitGroup{}
wg.Add(3)
for i := 0; i < 3; i++ {
go func(i int, wg *sync.WaitGroup) {
defer wg.Done()
_, err := xhttp.NewRequest("GET", "https://github.com/", xhttp.WithMiddlewares(logicMiddleware))
_, err := xhttp.NewRequest("GET", "https://github.com/", xhttp.WithMiddleware(logicMiddleware))
a.Equal(err, xhttp.ErrShutdown)
}(i, &wg)
}
Expand Down
2 changes: 1 addition & 1 deletion src/xhttp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func WithRetry(f RetryIfFunc, opts ...retry.Option) RequestOption {
}}
}

func WithMiddlewares(middlewares ...Middleware) RequestOption {
func WithMiddleware(middlewares ...Middleware) RequestOption {
return &funcRequestOption{func(o *RequestOptions) {
o.Middlewares = append(o.Middlewares, middlewares...)
}}
Expand Down

0 comments on commit f6a7390

Please sign in to comment.