|
|
|
@ -266,11 +266,11 @@ func (client *Client) invoke(ctx context.Context, req *http.Request, args interf |
|
|
|
|
|
|
|
|
|
// DoWithMiddleware send an HTTP request WithMiddleware and decodes the body of response into target.
|
|
|
|
|
// returns an error (of type *Error) if the response status code is not 2xx.
|
|
|
|
|
func (client *Client) DoWithMiddleware(req *http.Request, opts ...CallOption) (*http.Response, error) { |
|
|
|
|
func (client *Client) DoWithMiddleware(req *http.Request, reply interface{}, opts ...CallOption) error { |
|
|
|
|
c := defaultCallInfo(req.URL.Path) |
|
|
|
|
for _, o := range opts { |
|
|
|
|
if err := o.before(&c); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
h := func(ctx context.Context, in interface{}) (interface{}, error) { |
|
|
|
@ -284,21 +284,17 @@ func (client *Client) DoWithMiddleware(req *http.Request, opts ...CallOption) (* |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
return res, nil |
|
|
|
|
defer res.Body.Close() |
|
|
|
|
if err := client.opts.decoder(ctx, res, reply); err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
return reply, nil |
|
|
|
|
} |
|
|
|
|
if len(client.opts.middleware) > 0 { |
|
|
|
|
h = middleware.Chain(client.opts.middleware...)(h) |
|
|
|
|
} |
|
|
|
|
resp, err := h(req.Context(), req) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
response, ok := resp.(*http.Response) |
|
|
|
|
if ok { |
|
|
|
|
return response, nil |
|
|
|
|
} |
|
|
|
|
return nil, errors.New(500, "Client DoWithMiddleware Failed", "response convert failed ") |
|
|
|
|
_, err := h(req.Context(), req) |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Do send an HTTP request and decodes the body of response into target.
|
|
|
|
|