From e661eba314ee4a2e932277aba83b3af16dda4ce3 Mon Sep 17 00:00:00 2001 From: Maxim Korolyov Date: Mon, 28 Aug 2017 12:10:13 +0300 Subject: [PATCH] fixes #6. add support for golang 1.8.3 --- client.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client.go b/client.go index 65a4151..ce0feaf 100644 --- a/client.go +++ b/client.go @@ -9,6 +9,7 @@ import ( "bytes" "context" "encoding/json" + "io" "io/ioutil" "net/http" @@ -104,17 +105,17 @@ func OptEnv(env env) Option { // Call does HTTP request with given params using set HTTP client. Response will be decoded into respObj. // Error may be returned if something went wrong. If API return error as response, then Call returns error of type zooz.Error. func (c *Client) Call(ctx context.Context, method, path string, headers map[string]string, reqObj interface{}, respObj interface{}) (callErr error) { - var reqBody []byte - var err error + var reqBody io.Reader if reqObj != nil { - reqBody, err = json.Marshal(reqObj) + reqBodyBytes, err := json.Marshal(reqObj) if err != nil { return errors.Wrap(err, "failed to marshal request body") } + reqBody = bytes.NewBuffer(reqBodyBytes) } - req, err := http.NewRequest(method, apiURL+path, bytes.NewBuffer(reqBody)) + req, err := http.NewRequest(method, apiURL+path, reqBody) if err != nil { return errors.Wrap(err, "failed to create HTTP request") }