|
|
|
|
@@ -19,37 +19,31 @@ func NewHttpClient(baseURL string) *HttpClient {
|
|
|
|
|
|
|
|
|
|
func (c *HttpClient) SendGet(url string, data, out any) error {
|
|
|
|
|
fmt.Printf("Sending req to: %s%s\n", c.baseURL, url)
|
|
|
|
|
res, err := c.sendRequest(c.baseURL, url, http.MethodGet, data)
|
|
|
|
|
res, err := c.sendRequest(url, http.MethodGet, data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
decoder := json.NewDecoder(res.Body)
|
|
|
|
|
err = decoder.Decode(&out)
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
|
|
|
|
return decoder.Decode(&out)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *HttpClient) SendPost(url string, data, out any) error {
|
|
|
|
|
res, err := c.sendRequest(url, http.MethodPost, data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *HttpClient) SendPost(url string, data, out any) (any, error) {
|
|
|
|
|
res, err := c.sendRequest(c.baseURL, url, http.MethodPost, data)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
decoder := json.NewDecoder(res.Body)
|
|
|
|
|
err = decoder.Decode(out)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
|
|
|
|
return out, nil
|
|
|
|
|
return decoder.Decode(&out)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c *HttpClient) sendRequest(baseURL, actionURL, method string, data any) (*http.Response, error) {
|
|
|
|
|
apiUrl := baseURL + actionURL
|
|
|
|
|
func (c *HttpClient) sendRequest(url, method string, data any) (*http.Response, error) {
|
|
|
|
|
apiUrl := c.baseURL + url
|
|
|
|
|
|
|
|
|
|
tr := &http.Transport{
|
|
|
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // FIXME dev mode
|
|
|
|
|
@@ -74,7 +68,6 @@ func (c *HttpClient) sendRequest(baseURL, actionURL, method string, data any) (*
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
defer res.Body.Close()
|
|
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
|
}
|
|
|
|
|
|