From 9aa2134521e72a0cbe619e7948608416b2e13a32 Mon Sep 17 00:00:00 2001 From: Igor Dolzhikov Date: Sun, 26 Oct 2014 23:56:32 +0600 Subject: [PATCH] excluding of unused transformation to []byte A Readers are more flexible and result in faster code that uses less memory --- client/client.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/client/client.go b/client/client.go index 30c2ce7b..d40d85f3 100644 --- a/client/client.go +++ b/client/client.go @@ -90,12 +90,8 @@ func (c *Client) run(method, path string, in, out interface{}) error { return err } - // Read the bytes from the body (make sure we defer close the body) + // make sure we defer close the body defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - return err - } // Check for an http error status (ie not 200 StatusOK) switch resp.StatusCode { @@ -111,9 +107,9 @@ func (c *Client) run(method, path string, in, out interface{}) error { return ErrInternalServer } - // Unmarshall the JSON response + // Decode the JSON response if out != nil { - return json.Unmarshal(body, out) + return json.NewDecoder(resp.Body).Decode(out) } return nil