package main import ( "encoding/json" "fmt" "io" "net/http" "time" ) type Client struct { BaseURL string APIKey string HTTPClient *http.Client } func NewClient(baseURL, apiKey string) *Client { return &Client{ BaseURL: baseURL, APIKey: apiKey, HTTPClient: &http.Client{ Timeout: 30 * time.Second, }, } } func (c *Client) GetSystemStatus() (*SystemStatus, error) { // Create the URL for the system status endpoint. url := fmt.Sprintf("%s/api/v3/system/status", c.BaseURL) // Create a new GET request to the system status endpoint. req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } // Set the API key and content type headers. req.Header.Set("X-Api-Key", c.APIKey) req.Header.Set("Content-Type", "application/json") // Send the request and get the response. resp, err := c.HTTPClient.Do(req) if err != nil { return nil, fmt.Errorf("failed to send request: %w", err) } defer resp.Body.Close() // Check if the response is successful. if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("failed to get system status: %s", resp.Status) } // Read the response body. body, err := io.ReadAll(resp.Body) if err != nil { return nil, fmt.Errorf("failed to read response body: %w", err) } // Unmarshal the response body into a SystemStatus struct. var status SystemStatus if err := json.Unmarshal(body, &status); err != nil { return nil, fmt.Errorf("failed to unmarshal response body: %w", err) } // Return the SystemStatus struct. return &status, nil }