add logs
This commit is contained in:
@@ -3,11 +3,12 @@ package api
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/labstack/echo/v4"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func PostRequest(url string, model any, header http.Header) ([]byte, error, *http.Response) {
|
||||
func PostRequest(url string, model any, header http.Header, c echo.Context) ([]byte, error, *http.Response) {
|
||||
uJson, err := json.Marshal(model)
|
||||
|
||||
if err != nil {
|
||||
@@ -19,6 +20,13 @@ func PostRequest(url string, model any, header http.Header) ([]byte, error, *htt
|
||||
req.Header = header
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
debug, err := json.Marshal(req)
|
||||
|
||||
if err != nil {
|
||||
c.Logger().Debug("Request---")
|
||||
c.Logger().Debug(string(debug))
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
@@ -31,10 +39,17 @@ func PostRequest(url string, model any, header http.Header) ([]byte, error, *htt
|
||||
return nil, err, nil
|
||||
}
|
||||
|
||||
debug, err = json.Marshal(resp)
|
||||
|
||||
if err != nil {
|
||||
c.Logger().Debug("Response---")
|
||||
c.Logger().Debug(string(debug))
|
||||
}
|
||||
|
||||
return data, nil, resp
|
||||
}
|
||||
|
||||
func GetRequest(url string, header http.Header, args ...string) ([]byte, error, *http.Response) {
|
||||
func GetRequest(url string, header http.Header, c echo.Context, args ...string) ([]byte, error, *http.Response) {
|
||||
client := http.Client{}
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if len(args) > 0 {
|
||||
@@ -42,6 +57,14 @@ func GetRequest(url string, header http.Header, args ...string) ([]byte, error,
|
||||
}
|
||||
req.Header = header
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
debug, err := json.Marshal(req)
|
||||
|
||||
if err != nil {
|
||||
c.Logger().Debug("Request---")
|
||||
c.Logger().Debug(string(debug))
|
||||
}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
@@ -54,6 +77,11 @@ func GetRequest(url string, header http.Header, args ...string) ([]byte, error,
|
||||
return nil, err, nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.Logger().Debug("Response---")
|
||||
c.Logger().Debug(string(debug))
|
||||
}
|
||||
|
||||
return data, nil, resp
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user