summaryrefslogtreecommitdiffstats
path: root/golib
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
parent7496dbabaf710a9e0f3b599c83163adddfcb8870 (diff)
Commented exported functions or structures.
Diffstat (limited to 'golib')
-rw-r--r--golib/filepath.go2
-rw-r--r--golib/httpclient.go12
2 files changed, 8 insertions, 6 deletions
diff --git a/golib/filepath.go b/golib/filepath.go
index 5a923b4..90424d7 100644
--- a/golib/filepath.go
+++ b/golib/filepath.go
@@ -65,7 +65,7 @@ func ResolveEnvVar(s string) (string, error) {
return path.Clean(res), nil
}
-// PathNormalize
+// PathNormalize normalizes a linux or windows like path
func PathNormalize(p string) string {
sep := string(filepath.Separator)
if sep != "/" {
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)
}