forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetwork_pools.go
52 lines (45 loc) · 1.36 KB
/
network_pools.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
package linodego
import (
"context"
"fmt"
"net/url"
"github.com/go-resty/resty/v2"
)
// IPv6PoolsPagedResponse represents a paginated IPv6Pool API response
type IPv6PoolsPagedResponse struct {
*PageOptions
Data []IPv6Range `json:"data"`
}
// endpoint gets the endpoint URL for IPv6Pool
func (IPv6PoolsPagedResponse) endpoint(_ ...any) string {
return "networking/ipv6/pools"
}
func (resp *IPv6PoolsPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
res, err := coupleAPIErrors(r.SetResult(IPv6PoolsPagedResponse{}).Get(e))
if err != nil {
return 0, 0, err
}
castedRes := res.Result().(*IPv6PoolsPagedResponse)
resp.Data = append(resp.Data, castedRes.Data...)
return castedRes.Pages, castedRes.Results, nil
}
// ListIPv6Pools lists IPv6Pools
func (c *Client) ListIPv6Pools(ctx context.Context, opts *ListOptions) ([]IPv6Range, error) {
response := IPv6PoolsPagedResponse{}
err := c.listHelper(ctx, &response, opts)
if err != nil {
return nil, err
}
return response.Data, nil
}
// GetIPv6Pool gets the template with the provided ID
func (c *Client) GetIPv6Pool(ctx context.Context, id string) (*IPv6Range, error) {
id = url.PathEscape(id)
e := fmt.Sprintf("networking/ipv6/pools/%s", id)
req := c.R(ctx).SetResult(&IPv6Range{})
r, err := coupleAPIErrors(req.Get(e))
if err != nil {
return nil, err
}
return r.Result().(*IPv6Range), nil
}