github.com/arunkumar7540/cli@v6.45.0+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  
    17  // GetStacks lists stacks with optional filters.
    18  func (client *Client) GetStacks(query ...Query) ([]Stack, Warnings, error) {
    19  	request, err := client.newHTTPRequest(requestOptions{
    20  		RequestName: internal.GetStacksRequest,
    21  		Query:       query,
    22  	})
    23  	if err != nil {
    24  		return nil, nil, err
    25  	}
    26  
    27  	var fullStacksList []Stack
    28  	warnings, err := client.paginate(request, Stack{}, func(item interface{}) error {
    29  		if stack, ok := item.(Stack); ok {
    30  			fullStacksList = append(fullStacksList, stack)
    31  		} else {
    32  			return ccerror.UnknownObjectInListError{
    33  				Expected:   Stack{},
    34  				Unexpected: item,
    35  			}
    36  		}
    37  		return nil
    38  	})
    39  
    40  	return fullStacksList, warnings, err
    41  }