forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
longview.go
56 lines (48 loc) · 1.58 KB
/
longview.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package linodego
import (
"context"
"fmt"
"github.com/go-resty/resty/v2"
)
// LongviewClient represents a LongviewClient object
type LongviewClient struct {
ID int `json:"id"`
// UpdatedStr string `json:"updated"`
// Updated *time.Time `json:"-"`
}
// LongviewClientsPagedResponse represents a paginated LongviewClient API response
type LongviewClientsPagedResponse struct {
*PageOptions
Data []LongviewClient `json:"data"`
}
// endpoint gets the endpoint URL for LongviewClient
func (LongviewClientsPagedResponse) endpoint(_ ...any) string {
return "longview/clients"
}
func (resp *LongviewClientsPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
res, err := coupleAPIErrors(r.SetResult(LongviewClientsPagedResponse{}).Get(e))
if err != nil {
return 0, 0, err
}
castedRes := res.Result().(*LongviewClientsPagedResponse)
resp.Data = append(resp.Data, castedRes.Data...)
return castedRes.Pages, castedRes.Results, nil
}
// ListLongviewClients lists LongviewClients
func (c *Client) ListLongviewClients(ctx context.Context, opts *ListOptions) ([]LongviewClient, error) {
response := LongviewClientsPagedResponse{}
err := c.listHelper(ctx, &response, opts)
if err != nil {
return nil, err
}
return response.Data, nil
}
// GetLongviewClient gets the template with the provided ID
func (c *Client) GetLongviewClient(ctx context.Context, clientID string) (*LongviewClient, error) {
e := fmt.Sprintf("longview/clients/%s", clientID)
r, err := c.R(ctx).SetResult(&LongviewClient{}).Get(e)
if err != nil {
return nil, err
}
return r.Result().(*LongviewClient), nil
}