forked from linode/linodego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodebalancer_firewalls.go
41 lines (33 loc) · 1.19 KB
/
nodebalancer_firewalls.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
package linodego
import (
"context"
"fmt"
"github.com/go-resty/resty/v2"
)
// NodeBalancerFirewallsPagedResponse represents a Linode API response for listing of Cloud Firewalls
type NodeBalancerFirewallsPagedResponse struct {
*PageOptions
Data []Firewall `json:"data"`
}
func (NodeBalancerFirewallsPagedResponse) endpoint(ids ...any) string {
id := ids[0].(int)
return fmt.Sprintf("nodebalancers/%d/firewalls", id)
}
func (resp *NodeBalancerFirewallsPagedResponse) castResult(r *resty.Request, e string) (int, int, error) {
res, err := coupleAPIErrors(r.SetResult(NodeBalancerFirewallsPagedResponse{}).Get(e))
if err != nil {
return 0, 0, err
}
castedRes := res.Result().(*NodeBalancerFirewallsPagedResponse)
resp.Data = append(resp.Data, castedRes.Data...)
return castedRes.Pages, castedRes.Results, nil
}
// ListNodeBalancerFirewalls returns a paginated list of Cloud Firewalls for nodebalancerID
func (c *Client) ListNodeBalancerFirewalls(ctx context.Context, nodebalancerID int, opts *ListOptions) ([]Firewall, error) {
response := NodeBalancerFirewallsPagedResponse{}
err := c.listHelper(ctx, &response, opts, nodebalancerID)
if err != nil {
return nil, err
}
return response.Data, nil
}