github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/elb/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 additional parameters to the
     9  // List request.
    10  type ListOptsBuilder interface {
    11  	ToFlavorListMap() (string, error)
    12  }
    13  
    14  //ListOpts allows the filtering and sorting of paginated collections through the API.
    15  type ListOpts struct {
    16  	// Specifies the id.
    17  	ID []string `q:"id"`
    18  	// Specifies the name.
    19  	Name []string `q:"name"`
    20  	// Specifies whether shared.
    21  	Shared *bool `q:"shared"`
    22  	// Specifies the type.
    23  	Type []string `q:"type"`
    24  }
    25  
    26  // ToFlavorListMap formats a ListOpts into a query string.
    27  func (opts ListOpts) ToFlavorListMap() (string, error) {
    28  	s, err := golangsdk.BuildQueryString(opts)
    29  	if err != nil {
    30  		return "", err
    31  	}
    32  	return s.String(), err
    33  }
    34  
    35  // List returns a Pager which allows you to iterate over a collection of
    36  // flavors.
    37  func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    38  	url := listURL(c)
    39  	if opts != nil {
    40  		queryString, err := opts.ToFlavorListMap()
    41  		if err != nil {
    42  			return pagination.Pager{Err: err}
    43  		}
    44  		url += queryString
    45  	}
    46  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
    47  		return FlavorsPage{pagination.LinkedPageBase{PageResult: r}}
    48  	})
    49  }