-
Notifications
You must be signed in to change notification settings - Fork 83
/
longview.go
67 lines (59 loc) · 1.8 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
57
58
59
60
61
62
63
64
65
66
67
package linodego
import (
"context"
"fmt"
)
// 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(c *Client) string {
endpoint, err := c.LongviewClients.Endpoint()
if err != nil {
panic(err)
}
return endpoint
}
// appendData appends LongviewClients when processing paginated LongviewClient responses
func (resp *LongviewClientsPagedResponse) appendData(r *LongviewClientsPagedResponse) {
(*resp).Data = append(resp.Data, r.Data...)
}
// ListLongviewClients lists LongviewClients
func (c *Client) ListLongviewClients(ctx context.Context, opts *ListOptions) ([]*LongviewClient, error) {
response := LongviewClientsPagedResponse{}
err := c.listHelper(ctx, &response, opts)
for _, el := range response.Data {
el.fixDates()
}
if err != nil {
return nil, err
}
return response.Data, nil
}
// fixDates converts JSON timestamps to Go time.Time values
func (v *LongviewClient) fixDates() *LongviewClient {
// v.Created, _ = parseDates(v.CreatedStr)
// v.Updated, _ = parseDates(v.UpdatedStr)
return v
}
// GetLongviewClient gets the template with the provided ID
func (c *Client) GetLongviewClient(ctx context.Context, id string) (*LongviewClient, error) {
e, err := c.LongviewClients.Endpoint()
if err != nil {
return nil, err
}
e = fmt.Sprintf("%s/%s", e, id)
r, err := c.R(ctx).SetResult(&LongviewClient{}).Get(e)
if err != nil {
return nil, err
}
return r.Result().(*LongviewClient).fixDates(), nil
}