Replace implementation with kapow/http/response

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-10-03 14:10:48 +02:00
parent 6689ed458c
commit d259e3b411
+3 -20
View File
@@ -1,30 +1,13 @@
package client
import (
"errors"
"io"
"net/http"
"strings"
)
func getReason(r *http.Response) string {
return strings.Join(strings.Split(r.Status, " ")[1:], " ")
}
"github.com/BBVA/kapow/http"
)
//GetData will perform the request and write the results on the provided writer
func GetData(host, id, path string, wr io.Writer) error {
url := host + "/handlers/" + id + path
res, err := http.Get(url)
if err != nil {
return err
}
defer res.Body.Close()
if res.StatusCode < 200 || res.StatusCode >= 300 {
return errors.New(getReason(res))
}
_, err = io.Copy(wr, res.Body)
return err
return http.Do("GET", url, nil, wr)
}