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

     1  package flavors
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  // ListOptsBuilder allows extensions to add parameters to the List request.
     9  type ListOptsBuilder interface {
    10  	ToFlavorListQuery() (string, error)
    11  }
    12  
    13  // ListOpts allows the filtering and sorting of paginated collections through
    14  // the API. Filtering is achieved by passing in struct field values that map to
    15  // the server attributes you want to see returned. Marker and Limit are used
    16  // for pagination.
    17  type ListOpts struct {
    18  	Region     string `q:"region"`
    19  	EngineName string `q:"engine_name"`
    20  }
    21  
    22  // ToFlavorListQuery formats a ListOpts into a query string.
    23  func (opts ListOpts) ToFlavorListQuery() (string, error) {
    24  	q, err := golangsdk.BuildQueryString(opts)
    25  	return q.String(), err
    26  }
    27  
    28  // List implements a flavor List request.
    29  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    30  	url := baseURL(client)
    31  	if opts != nil {
    32  		query, err := opts.ToFlavorListQuery()
    33  		if err != nil {
    34  			return pagination.Pager{Err: err}
    35  		}
    36  		url += query
    37  	}
    38  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    39  		return FlavorPage{pagination.LinkedPageBase{PageResult: r}}
    40  	})
    41  }