github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/api/cloudcontroller/ccv3/space.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  // Space represents a Cloud Controller V3 Space.
     9  type Space struct {
    10  	Name string `json:"name"`
    11  	GUID string `json:"guid"`
    12  }
    13  
    14  // GetSpaces lists spaces with optional filters.
    15  func (client *Client) GetSpaces(query ...Query) ([]Space, Warnings, error) {
    16  	request, err := client.newHTTPRequest(requestOptions{
    17  		RequestName: internal.GetSpacesRequest,
    18  		Query:       query,
    19  	})
    20  	if err != nil {
    21  		return nil, nil, err
    22  	}
    23  
    24  	var fullSpacesList []Space
    25  	warnings, err := client.paginate(request, Space{}, func(item interface{}) error {
    26  		if space, ok := item.(Space); ok {
    27  			fullSpacesList = append(fullSpacesList, space)
    28  		} else {
    29  			return ccerror.UnknownObjectInListError{
    30  				Expected:   Space{},
    31  				Unexpected: item,
    32  			}
    33  		}
    34  		return nil
    35  	})
    36  
    37  	return fullSpacesList, warnings, err
    38  }