diff --git a/api/rest/http.go b/api/rest/http.go index 7feabe9..d5c802f 100644 --- a/api/rest/http.go +++ b/api/rest/http.go @@ -4,6 +4,7 @@ import ( "bytes" "crypto/tls" "encoding/json" + "fmt" "net/http" ) @@ -12,12 +13,13 @@ type HttpClient struct { userAgent string } -func NewHttpClient(apiURL string) *HttpClient { - return &HttpClient{baseURL: apiURL, userAgent: "internal-http-client"} +func NewHttpClient(baseURL string) *HttpClient { + return &HttpClient{baseURL: baseURL, userAgent: "internal-http-client"} } -func (c *HttpClient) SendGet(api, url string, data, out any) error { - res, err := c.sendRequest(api, url, http.MethodGet, data) +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) if err != nil { return err } @@ -31,8 +33,8 @@ func (c *HttpClient) SendGet(api, url string, data, out any) error { return nil } -func (c *HttpClient) SendPost(api, url string, data, out any) (any, error) { - res, err := c.sendRequest(api, url, http.MethodPost, data) +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 } @@ -46,15 +48,15 @@ func (c *HttpClient) SendPost(api, url string, data, out any) (any, error) { return out, nil } -func (c *HttpClient) sendRequest(api, url, method string, data any) (*http.Response, error) { - apiUrl := api + url // FIXME +func (c *HttpClient) sendRequest(baseURL, actionURL, method string, data any) (*http.Response, error) { + apiUrl := baseURL + actionURL tr := &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // FIXME + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, // FIXME dev mode } // Create an HTTP client with the custom transport - client := &http.Client{Transport: tr} // FIXME + client := &http.Client{Transport: tr} // FIXME dev mode json, err := json.Marshal(&data) if err != nil {