diff --git a/v1/client.go b/v1/client.go index 7994c62..0fb4e7b 100644 --- a/v1/client.go +++ b/v1/client.go @@ -12,9 +12,9 @@ import ( // New initialize client func New(url string, token string) *MgClient { return &MgClient{ - url, - token, - &http.Client{Timeout: 20 * time.Second}, + URL: url, + Token: token, + httpClient: &http.Client{Timeout: 20 * time.Second}, } } diff --git a/v1/request.go b/v1/request.go index f04cace..6dfa1ed 100644 --- a/v1/request.go +++ b/v1/request.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "io/ioutil" + "log" "net/http" ) @@ -78,6 +79,10 @@ func makeRequest(reqType, url string, buf *bytes.Buffer, c *MgClient) ([]byte, i req.Header.Set("Content-Type", "application/json") req.Header.Set("X-Transport-Token", c.Token) + if c.Debug { + log.Printf("MG TRANSPORT API Request: %s %s %s %s", reqType, url, c.Token, buf.String()) + } + resp, err := c.httpClient.Do(req) if err != nil { return res, 0, err @@ -93,6 +98,10 @@ func makeRequest(reqType, url string, buf *bytes.Buffer, c *MgClient) ([]byte, i return res, 0, err } + if c.Debug { + log.Printf("MG TRANSPORT API Response: %s", res) + } + return res, resp.StatusCode, err } diff --git a/v1/types.go b/v1/types.go index 29601f7..5f57386 100644 --- a/v1/types.go +++ b/v1/types.go @@ -7,9 +7,10 @@ import ( // MgClient type type MgClient struct { - URL string - Token string - httpClient *http.Client + URL string `json:"url"` + Token string `json:"token"` + Debug bool `json:"debug"` + httpClient *http.Client `json:"-"` } // Channel type