Replace implementation with kapow/http/response
This commit is contained in:
+3
-20
@@ -1,30 +1,13 @@
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getReason(r *http.Response) string {
|
"github.com/BBVA/kapow/http"
|
||||||
return strings.Join(strings.Split(r.Status, " ")[1:], " ")
|
)
|
||||||
}
|
|
||||||
|
|
||||||
//GetData will perform the request and write the results on the provided writer
|
//GetData will perform the request and write the results on the provided writer
|
||||||
func GetData(host, id, path string, wr io.Writer) error {
|
func GetData(host, id, path string, wr io.Writer) error {
|
||||||
url := host + "/handlers/" + id + path
|
url := host + "/handlers/" + id + path
|
||||||
|
return http.Do("GET", url, nil, wr)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user