Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 58cb86af97 | |||
| 11900eeecd |
@@ -2,7 +2,9 @@ package api
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
@@ -11,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
|
||||
}
|
||||
@@ -30,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
|
||||
}
|
||||
@@ -45,9 +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
|
||||
client := &http.Client{}
|
||||
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 dev mode
|
||||
}
|
||||
|
||||
// Create an HTTP client with the custom transport
|
||||
client := &http.Client{Transport: tr} // FIXME dev mode
|
||||
|
||||
json, err := json.Marshal(&data)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user