github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/api/cloudcontroller/ccv3/stack.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  type Stack struct {
     9  	// GUID is a unique stack identifier.
    10  	GUID string `json:"guid"`
    11  	// Name is the name of the stack.
    12  	Name string `json:"name"`
    13  	// Description is the description for the stack
    14  	Description string `json:"description"`
    15  
    16  	// Metadata is used for custom tagging of API resources
    17  	Metadata *Metadata `json:"metadata,omitempty"`
    18  }
    19  
    20  // GetStacks lists stacks with optional filters.
    21  func (client *Client) GetStacks(query ...Query) ([]Stack, Warnings, error) {
    22  	request, err := client.newHTTPRequest(requestOptions{
    23  		RequestName: internal.GetStacksRequest,
    24  		Query:       query,
    25  	})
    26  	if err != nil {
    27  		return nil, nil, err
    28  	}
    29  
    30  	var fullStacksList []Stack
    31  	warnings, err := client.paginate(request, Stack{}, func(item interface{}) error {
    32  		if stack, ok := item.(Stack); ok {
    33  			fullStacksList = append(fullStacksList, stack)
    34  		} else {
    35  			return ccerror.UnknownObjectInListError{
    36  				Expected:   Stack{},
    37  				Unexpected: item,
    38  			}
    39  		}
    40  		return nil
    41  	})
    42  
    43  	return fullStacksList, warnings, err
    44  }