mirror of
https://github.com/Xevion/vastly.git
synced 2025-12-08 08:09:06 -06:00
repo init
This commit is contained in:
52
api/instances.go
Normal file
52
api/instances.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// InstanceGetResponse represents the response from GET /instances
|
||||
type InstanceGetResponse struct {
|
||||
Instances []Instance `json:"instances"`
|
||||
}
|
||||
|
||||
// GetInstances retrieves all instances for the authenticated user
|
||||
func (c *Client) GetInstances() (*InstanceGetResponse, error) {
|
||||
resp, err := c.makeRequest(http.MethodGet, "/instances", nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
var result InstanceGetResponse
|
||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
// DeleteInstance removes an instance by ID
|
||||
func (c *Client) DeleteInstance(id int) error {
|
||||
path := fmt.Sprintf("/instances/%d", id)
|
||||
resp, err := c.makeRequest(http.MethodDelete, path, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
resp.Body.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
// PutInstance updates an instance's status
|
||||
func (c *Client) PutInstance(id int, status string) error {
|
||||
path := fmt.Sprintf("/instances/%d", id)
|
||||
data := map[string]string{"status": status}
|
||||
|
||||
resp, err := c.makeRequest(http.MethodPut, path, data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
resp.Body.Close()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user