forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vlans.go
65 lines (52 loc) · 1.26 KB
/
vlans.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
package linodego
import (
"context"
"encoding/json"
"time"
"github.com/linode/linodego/internal/parseabletime"
)
type VLAN struct {
Label string `json:"label"`
Linodes []int `json:"linodes"`
Region string `json:"region"`
Created *time.Time `json:"-"`
}
// UnmarshalJSON for VLAN responses
func (v *VLAN) UnmarshalJSON(b []byte) error {
type Mask VLAN
p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
}{
Mask: (*Mask)(v),
}
if err := json.Unmarshal(b, &p); err != nil {
return err
}
v.Created = (*time.Time)(p.Created)
return nil
}
// VLANsPagedResponse represents a Linode API response for listing of VLANs
type VLANsPagedResponse struct {
*PageOptions
Data []VLAN `json:"data"`
}
func (VLANsPagedResponse) endpoint(c *Client) string {
endpoint, err := c.VLANs.Endpoint()
if err != nil {
panic(err)
}
return endpoint
}
func (resp *VLANsPagedResponse) appendData(r *VLANsPagedResponse) {
resp.Data = append(resp.Data, r.Data...)
}
// ListVLANs returns a paginated list of VLANs
func (c *Client) ListVLANs(ctx context.Context, opts *ListOptions) ([]VLAN, error) {
response := VLANsPagedResponse{}
err := c.listHelper(ctx, &response, opts)
if err != nil {
return nil, err
}
return response.Data, nil
}