github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/dcs/v2/flavors/requests.go (about)

     1  package flavors
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  )
     6  
     7  // ListOptsBuilder allows extensions to add parameters to the List request.
     8  type ListOptsBuilder interface {
     9  	ToFlavorListQuery() (string, error)
    10  }
    11  
    12  // ListOpts allows the filtering and sorting of paginated collections through
    13  // the API. Filtering is achieved by passing in struct field values that map to
    14  // the server attributes you want to see returned.
    15  type ListOpts struct {
    16  	CacheMode     string `q:"cache_mode"`
    17  	Engine        string `q:"engine"`
    18  	EngineVersion string `q:"engine_version"`
    19  	Capacity      string `q:"capacity"`
    20  	SpecCode      string `q:"spec_code"`
    21  	CPUType       string `q:"cpu_type"`
    22  }
    23  
    24  // ToFlavorListQuery formats a ListOpts into a query string.
    25  func (opts ListOpts) ToFlavorListQuery() (string, error) {
    26  	q, err := golangsdk.BuildQueryString(opts)
    27  	return q.String(), err
    28  }
    29  
    30  // List implements a flavor List request.
    31  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) (r ListResult) {
    32  	url := listURL(client)
    33  	if opts != nil {
    34  		query, err := opts.ToFlavorListQuery()
    35  		if err != nil {
    36  			r.Err = err
    37  			return
    38  		}
    39  		url += query
    40  	}
    41  	_, r.Err = client.Get(url, &r.Body, nil)
    42  	return
    43  }