|
|
@ -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.
|
|
|
|
// 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.
|
|
|
|
// 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) |
|
|
|
c := defaultCallInfo(req.URL.Path) |
|
|
|
for _, o := range opts { |
|
|
|
for _, o := range opts { |
|
|
|
if err := o.before(&c); err != nil { |
|
|
|
if err := o.before(&c); err != nil { |
|
|
|
return nil, err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
h := func(ctx context.Context, in interface{}) (interface{}, error) { |
|
|
|
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 { |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
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 { |
|
|
|
if len(client.opts.middleware) > 0 { |
|
|
|
h = middleware.Chain(client.opts.middleware...)(h) |
|
|
|
h = middleware.Chain(client.opts.middleware...)(h) |
|
|
|
} |
|
|
|
} |
|
|
|
resp, err := h(req.Context(), req) |
|
|
|
_, err := h(req.Context(), req) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
response, ok := resp.(*http.Response) |
|
|
|
|
|
|
|
if ok { |
|
|
|
|
|
|
|
return response, nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return nil, errors.New(500, "Client DoWithMiddleware Failed", "response convert failed ") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Do send an HTTP request and decodes the body of response into target.
|
|
|
|
// Do send an HTTP request and decodes the body of response into target.
|
|
|
|