Skip to content

Commit

Permalink
PrimaryIPClient Add AllWithOpts
Browse files Browse the repository at this point in the history
This was missed when implementing the primary ip client.

Signed-off-by: Lukas Kämmerling <lukas.kaemmerling@hetzner-cloud.de>
  • Loading branch information
LKaemmerling committed Nov 9, 2022
1 parent 55dafa9 commit ad45e49
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions hcloud/primary_ip.go
Expand Up @@ -240,18 +240,20 @@ func (c *PrimaryIPClient) List(ctx context.Context, opts PrimaryIPListOpts) ([]*

// All returns all Primary IPs.
func (c *PrimaryIPClient) All(ctx context.Context) ([]*PrimaryIP, error) {
allPrimaryIPs := []*PrimaryIP{}
return c.AllWithOpts(ctx, PrimaryIPListOpts{ListOpts: ListOpts{PerPage: 50}})
}

opts := PrimaryIPListOpts{}
opts.PerPage = 50
// AllWithOpts returns all Primary IPs for the given options.
func (c *PrimaryIPClient) AllWithOpts(ctx context.Context, opts PrimaryIPListOpts) ([]*PrimaryIP, error) {
var allPrimaryIPs []*PrimaryIP

err := c.client.all(func(page int) (*Response, error) {
opts.Page = page
primaryIPs, resp, err := c.List(ctx, opts)
if err != nil {
return resp, err
}
allPrimaryIPs = append(allPrimaryIPs, primaryIPs...)
primaryIPs = append(allPrimaryIPs, primaryIPs...)
return resp, nil
})
if err != nil {
Expand Down

0 comments on commit ad45e49

Please sign in to comment.