github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/ecs/v1/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 AZ name. 17 AvailabilityZone string `q:"availability_zone"` 18 } 19 20 // ToFlavorListMap formats a ListOpts into a query string. 21 func (opts ListOpts) ToFlavorListMap() (string, error) { 22 s, err := golangsdk.BuildQueryString(opts) 23 if err != nil { 24 return "", err 25 } 26 return s.String(), err 27 } 28 29 // List returns a Pager which allows you to iterate over a collection of 30 // flavors. 31 func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 32 url := listURL(c) 33 if opts != nil { 34 queryString, err := opts.ToFlavorListMap() 35 if err != nil { 36 return pagination.Pager{Err: err} 37 } 38 url += queryString 39 } 40 return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { 41 return FlavorsPage{pagination.LinkedPageBase{PageResult: r}} 42 }) 43 }