Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 58cb86af97 |
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,12 +13,13 @@ type HttpClient struct {
|
|||||||
userAgent string
|
userAgent string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHttpClient(apiURL string) *HttpClient {
|
func NewHttpClient(baseURL string) *HttpClient {
|
||||||
return &HttpClient{baseURL: apiURL, userAgent: "internal-http-client"}
|
return &HttpClient{baseURL: baseURL, userAgent: "internal-http-client"}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HttpClient) SendGet(api, url string, data, out any) error {
|
func (c *HttpClient) SendGet(url string, data, out any) error {
|
||||||
res, err := c.sendRequest(api, url, http.MethodGet, data)
|
fmt.Printf("Sending req to: %s%s\n", c.baseURL, url)
|
||||||
|
res, err := c.sendRequest(c.baseURL, url, http.MethodGet, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -31,8 +33,8 @@ func (c *HttpClient) SendGet(api, url string, data, out any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HttpClient) SendPost(api, url string, data, out any) (any, error) {
|
func (c *HttpClient) SendPost(url string, data, out any) (any, error) {
|
||||||
res, err := c.sendRequest(api, url, http.MethodPost, data)
|
res, err := c.sendRequest(c.baseURL, url, http.MethodPost, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -46,15 +48,15 @@ func (c *HttpClient) SendPost(api, url string, data, out any) (any, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HttpClient) sendRequest(api, url, method string, data any) (*http.Response, error) {
|
func (c *HttpClient) sendRequest(baseURL, actionURL, method string, data any) (*http.Response, error) {
|
||||||
apiUrl := api + url // FIXME
|
apiUrl := baseURL + actionURL
|
||||||
|
|
||||||
tr := &http.Transport{
|
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
|
// 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)
|
json, err := json.Marshal(&data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user