Skip to content

Commit c1405c8

Browse files
author
Derek Dowling
committed
Adding body convenience func
1 parent 4f82614 commit c1405c8

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

client.go

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package jsh
33
import (
44
"encoding/json"
55
"fmt"
6+
"io/ioutil"
67
"net/http"
78
"net/url"
89
"strconv"
@@ -32,6 +33,18 @@ func (c *ClientResponse) GetList() ([]*Object, SendableError) {
3233
return parseMany(c.Header, c.Body)
3334
}
3435

36+
// BodyStr is a convenience function that parses the body of the response into a
37+
// string BUT DOESN'T close the ReadCloser
38+
func (c *ClientResponse) BodyStr() (string, error) {
39+
40+
byteData, err := ioutil.ReadAll(c.Body)
41+
if err != nil {
42+
return "", fmt.Errorf("Error attempting to read request body: %s", err)
43+
}
44+
45+
return string(byteData), nil
46+
}
47+
3548
// Send sends an http.Request and handles parsing the response back
3649
func (r *Request) Send() (*ClientResponse, error) {
3750
client := &http.Client{}

0 commit comments

Comments
 (0)