github.com/ablease/cli@v6.37.1-0.20180613014814-3adbb7d7fb19+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  	// GUID is a unique space identifier.
    11  	GUID string `json:"guid"`
    12  	// Name is the name of the space.
    13  	Name string `json:"name"`
    14  }
    15  
    16  // GetSpaces lists spaces with optional filters.
    17  func (client *Client) GetSpaces(query ...Query) ([]Space, Warnings, error) {
    18  	request, err := client.newHTTPRequest(requestOptions{
    19  		RequestName: internal.GetSpacesRequest,
    20  		Query:       query,
    21  	})
    22  	if err != nil {
    23  		return nil, nil, err
    24  	}
    25  
    26  	var fullSpacesList []Space
    27  	warnings, err := client.paginate(request, Space{}, func(item interface{}) error {
    28  		if space, ok := item.(Space); ok {
    29  			fullSpacesList = append(fullSpacesList, space)
    30  		} else {
    31  			return ccerror.UnknownObjectInListError{
    32  				Expected:   Space{},
    33  				Unexpected: item,
    34  			}
    35  		}
    36  		return nil
    37  	})
    38  
    39  	return fullSpacesList, warnings, err
    40  }