"fmt"
"io"
"net/http"
+
+ log "github.com/sirupsen/logrus"
)
type Client struct {
}
}
-type HTTPClient interface {
- Get(path string, v interface{}) error
- Post(path string, payload interface{}, v interface{}) error
-}
-
func (c *Client) Get(path string, v interface{}) error {
req, err := c.newRequest(http.MethodGet, path, nil)
if err != nil {
}
func (c *Client) Post(path string, payload interface{}, v interface{}) error {
+
+ s, _ := json.MarshalIndent(payload, "", "\t")
+ log.Debugf("Post request payload: " + string(s))
+
req, err := c.newRequest(http.MethodPost, path, payload)
if err != nil {
return fmt.Errorf("failed to create POST request: %w", err)
if reqBody != nil {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
}
- fmt.Printf("Http Client Request: [%s:%s]\n", req.Method, req.URL)
+ log.Debugf("Http Client Request: [%s:%s]\n", req.Method, req.URL)
return req, nil
}
if err := dec.Decode(v); err != nil {
return fmt.Errorf("could not parse response body: %w [%s:%s]", err, r.Method, r.URL.String())
}
- fmt.Printf("Http Client Response: %+v\n", v)
+ log.Debugf("Http Client Response: %v\n", v)
return nil
}