Code Review
/
nonrtric.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Fixing bug in O-DU slice assurance app
[nonrtric.git]
/
test
/
usecases
/
odusliceassurance
/
goversion
/
internal
/
restclient
/
client.go
diff --git
a/test/usecases/odusliceassurance/goversion/internal/restclient/client.go
b/test/usecases/odusliceassurance/goversion/internal/restclient/client.go
index
81e1143
..
3983840
100644
(file)
--- a/
test/usecases/odusliceassurance/goversion/internal/restclient/client.go
+++ b/
test/usecases/odusliceassurance/goversion/internal/restclient/client.go
@@
-26,6
+26,8
@@
import (
"fmt"
"io"
"net/http"
"fmt"
"io"
"net/http"
+
+ log "github.com/sirupsen/logrus"
)
type Client struct {
)
type Client struct {
@@
-38,11
+40,6
@@
func New(httpClient *http.Client) *Client {
}
}
}
}
-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) Get(path string, v interface{}) error {
req, err := c.newRequest(http.MethodGet, path, nil)
if err != nil {
@@
-57,6
+54,10
@@
func (c *Client) Get(path string, v interface{}) error {
}
func (c *Client) Post(path string, payload interface{}, v interface{}) error {
}
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)
req, err := c.newRequest(http.MethodPost, path, payload)
if err != nil {
return fmt.Errorf("failed to create POST request: %w", err)
@@
-87,7
+88,7
@@
func (c *Client) newRequest(method, path string, payload interface{}) (*http.Req
if reqBody != nil {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
}
if reqBody != nil {
req.Header.Set("Content-Type", "application/json; charset=utf-8")
}
-
fmt.Print
f("Http Client Request: [%s:%s]\n", req.Method, req.URL)
+
log.Debug
f("Http Client Request: [%s:%s]\n", req.Method, req.URL)
return req, nil
}
return req, nil
}
@@
-110,7
+111,7
@@
func (c *Client) doRequest(r *http.Request, v interface{}) error {
if err := dec.Decode(v); err != nil {
return fmt.Errorf("could not parse response body: %w [%s:%s]", err, r.Method, r.URL.String())
}
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
}
return nil
}