github.com/chnsz/golangsdk@v0.0.0-20240506093406-85a3fbfa605b/openstack/dds/v3/flavors/requests.go (about)

     1  package flavors
     2  
     3  import (
     4  	"github.com/chnsz/golangsdk"
     5  	"github.com/chnsz/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  	EngineVersion string `q:"engine_version"`
    21  }
    22  
    23  // ToFlavorListQuery formats a ListOpts into a query string.
    24  func (opts ListOpts) ToFlavorListQuery() (string, error) {
    25  	q, err := golangsdk.BuildQueryString(opts)
    26  	return q.String(), err
    27  }
    28  
    29  // List implements a flavor List request.
    30  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    31  	url := baseURL(client)
    32  	if opts != nil {
    33  		query, err := opts.ToFlavorListQuery()
    34  		if err != nil {
    35  			return pagination.Pager{Err: err}
    36  		}
    37  		url += query
    38  	}
    39  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    40  		return FlavorPage{pagination.LinkedPageBase{PageResult: r}}
    41  	})
    42  }