Handle pagination in list calls
masterAll list calls in GoVultr v2 return a Meta struct containing pagination information. To navigate through large result sets, use the Links provided in the Meta object.
Pagination Details
Meta.Total: The total number of items in the list.Meta.Links.Next: The cursor string to use for the next page.Meta.Links.Prev: The cursor string for the previous page.ListOptions.PerPage: Controls the number of items per call. The default is100, and the maximum is500.
To iterate through all pages, update the Cursor field in your ListOptions with the value from meta.Links.Next until it is empty.
listOptions := &govultr.ListOptions{PerPage: 1}
for {
i, meta, err := client.Instance.List(ctx, listOptions)
if err != nil {
return nil, err
}
for _, v := range i {
fmt.Println(v)
}
if meta.Links.Next == "" {
break
} else {
listOptions.Cursor = meta.Links.Next
continue
}
}