github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/api/cloudcontroller/ccv3/service_instance.go (about)

     1  package ccv3
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     5  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/internal"
     6  )
     7  
     8  // ServiceInstance represents a Cloud Controller V3 Service Instance.
     9  type ServiceInstance struct {
    10  	// GUID is a unique service instance identifier.
    11  	GUID string `json:"guid"`
    12  	// Name is the name of the service instance.
    13  	Name string `json:"name"`
    14  }
    15  
    16  // GetServiceInstances lists service instances with optional filters.
    17  func (client *Client) GetServiceInstances(query ...Query) ([]ServiceInstance, Warnings, error) {
    18  	request, err := client.newHTTPRequest(requestOptions{
    19  		RequestName: internal.GetServiceInstancesRequest,
    20  		Query:       query,
    21  	})
    22  	if err != nil {
    23  		return nil, nil, err
    24  	}
    25  
    26  	var fullServiceInstanceList []ServiceInstance
    27  	warnings, err := client.paginate(request, ServiceInstance{}, func(item interface{}) error {
    28  		if serviceInstance, ok := item.(ServiceInstance); ok {
    29  			fullServiceInstanceList = append(fullServiceInstanceList, serviceInstance)
    30  		} else {
    31  			return ccerror.UnknownObjectInListError{
    32  				Expected:   ServiceInstance{},
    33  				Unexpected: item,
    34  			}
    35  		}
    36  		return nil
    37  	})
    38  
    39  	return fullServiceInstanceList, warnings, err
    40  }