aboutsummaryrefslogtreecommitdiffstats
path: root/golib/httpclient.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-08-08 09:35:50 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-08-08 09:35:50 +0200
commit731872ff3f9616da2a4555e9b5f61a07ab9f399a (patch)
treece9bae37989b55ef70cdc2c2d4d9e3c6e1fc8a51 /golib/httpclient.go
parent7496dbabaf710a9e0f3b599c83163adddfcb8870 (diff)
Commented exported functions or structures.
Diffstat (limited to 'golib/httpclient.go')
-rw-r--r--golib/httpclient.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/golib/httpclient.go b/golib/httpclient.go
index 597760c..026272e 100644
--- a/golib/httpclient.go
+++ b/golib/httpclient.go
@@ -13,6 +13,7 @@ import (
"github.com/Sirupsen/logrus"
)
+// HTTPClient .
type HTTPClient struct {
httpClient http.Client
endpoint string
@@ -25,6 +26,7 @@ type HTTPClient struct {
logger *logrus.Logger
}
+// HTTPClientConfig is used to config HTTPClient
type HTTPClientConfig struct {
URLPrefix string
HeaderAPIKeyName string
@@ -181,6 +183,7 @@ func (c *HTTPClient) HTTPPostWithRes(url string, body string) (*http.Response, e
return res, nil
}
+// ResponseToBArray converts an Http response to a byte array
func (c *HTTPClient) ResponseToBArray(response *http.Response) []byte {
defer response.Body.Close()
bytes, err := ioutil.ReadAll(response.Body)
@@ -245,11 +248,10 @@ csrffound:
json.Unmarshal(c.ResponseToBArray(response), &data)
if err, found := data["error"]; found {
return nil, fmt.Errorf(err.(string))
- } else {
- body := strings.TrimSpace(string(c.ResponseToBArray(response)))
- if body != "" {
- return nil, fmt.Errorf(body)
- }
+ }
+ body := strings.TrimSpace(string(c.ResponseToBArray(response)))
+ if body != "" {
+ return nil, fmt.Errorf(body)
}
return nil, errors.New("Unknown HTTP status returned: " + response.Status)
}