feat: initial implementation with docs and system_config
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
HostURL string
|
||||
HTTPClient *http.Client
|
||||
Token string
|
||||
}
|
||||
|
||||
func NewClient(host, token string) *Client {
|
||||
return &Client{
|
||||
HTTPClient: &http.Client{},
|
||||
HostURL: host,
|
||||
Token: token,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) doRequest(req *http.Request) ([]byte, error) {
|
||||
req.Header.Set("x-api-key", c.Token)
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
res, err := c.HTTPClient.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
||||
return nil, fmt.Errorf("status: %d, body: %s", res.StatusCode, string(body))
|
||||
}
|
||||
|
||||
return body, nil
|
||||
}
|
||||
Reference in New Issue
Block a user