commit
86ea1ad66a
@ -12,9 +12,9 @@ import (
|
|||||||
// New initialize client
|
// New initialize client
|
||||||
func New(url string, token string) *MgClient {
|
func New(url string, token string) *MgClient {
|
||||||
return &MgClient{
|
return &MgClient{
|
||||||
url,
|
URL: url,
|
||||||
token,
|
Token: token,
|
||||||
&http.Client{Timeout: 20 * time.Second},
|
httpClient: &http.Client{Timeout: 20 * time.Second},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"net/http"
|
"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("Content-Type", "application/json")
|
||||||
req.Header.Set("X-Transport-Token", c.Token)
|
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)
|
resp, err := c.httpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, 0, err
|
return res, 0, err
|
||||||
@ -93,6 +98,10 @@ func makeRequest(reqType, url string, buf *bytes.Buffer, c *MgClient) ([]byte, i
|
|||||||
return res, 0, err
|
return res, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.Debug {
|
||||||
|
log.Printf("MG TRANSPORT API Response: %s", res)
|
||||||
|
}
|
||||||
|
|
||||||
return res, resp.StatusCode, err
|
return res, resp.StatusCode, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,10 @@ import (
|
|||||||
|
|
||||||
// MgClient type
|
// MgClient type
|
||||||
type MgClient struct {
|
type MgClient struct {
|
||||||
URL string
|
URL string `json:"url"`
|
||||||
Token string
|
Token string `json:"token"`
|
||||||
httpClient *http.Client
|
Debug bool `json:"debug"`
|
||||||
|
httpClient *http.Client `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Channel type
|
// Channel type
|
||||||
|
Loading…
Reference in New Issue
Block a user