forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
paginate.go
50 lines (40 loc) · 1022 Bytes
/
paginate.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
package ccv2
import (
"net/http"
"code.cloudfoundry.org/cli/api/cloudcontroller"
)
func (client Client) paginate(request *cloudcontroller.Request, obj interface{}, appendToExternalList func(interface{}) error) (Warnings, error) {
fullWarningsList := Warnings{}
for {
wrapper := NewPaginatedResources(obj)
response := cloudcontroller.Response{
Result: &wrapper,
}
err := client.connection.Make(request, &response)
fullWarningsList = append(fullWarningsList, response.Warnings...)
if err != nil {
return fullWarningsList, err
}
list, err := wrapper.Resources()
if err != nil {
return fullWarningsList, err
}
for _, item := range list {
err = appendToExternalList(item)
if err != nil {
return fullWarningsList, err
}
}
if wrapper.NextURL == "" {
break
}
request, err = client.newHTTPRequest(requestOptions{
URI: wrapper.NextURL,
Method: http.MethodGet,
})
if err != nil {
return fullWarningsList, err
}
}
return fullWarningsList, nil
}