/
service_instance.go
40 lines (35 loc) · 1.18 KB
/
service_instance.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
package ccv3
import (
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
)
// ServiceInstance represents a Cloud Controller V3 Service Instance.
type ServiceInstance struct {
// GUID is a unique service instance identifier.
GUID string `json:"guid"`
// Name is the name of the service instance.
Name string `json:"name"`
}
// GetServiceInstances lists service instances with optional filters.
func (client *Client) GetServiceInstances(query ...Query) ([]ServiceInstance, Warnings, error) {
request, err := client.newHTTPRequest(requestOptions{
RequestName: internal.GetServiceInstancesRequest,
Query: query,
})
if err != nil {
return nil, nil, err
}
var fullServiceInstanceList []ServiceInstance
warnings, err := client.paginate(request, ServiceInstance{}, func(item interface{}) error {
if serviceInstance, ok := item.(ServiceInstance); ok {
fullServiceInstanceList = append(fullServiceInstanceList, serviceInstance)
} else {
return ccerror.UnknownObjectInListError{
Expected: ServiceInstance{},
Unexpected: item,
}
}
return nil
})
return fullServiceInstanceList, warnings, err
}