github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/elb/v3/flavors/requests.go (about)

     1  package flavors
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/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(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    38  	url := listURL(client)
    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(client, url, func(r pagination.PageResult) pagination.Page {
    47  		return FlavorPage{PageWithInfo: pagination.NewPageWithInfo(r)}
    48  	})
    49  }
    50  
    51  // Get returns additional information about a Flavor, given its ID.
    52  func Get(client *golangsdk.ServiceClient, flavorID string) (r GetResult) {
    53  	_, r.Err = client.Get(getURL(client, flavorID), &r.Body, nil)
    54  	return
    55  }