github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/providers/requests.go (about)

     1  package providers
     2  
     3  import (
     4  	"github.com/gophercloud/gophercloud"
     5  	"github.com/gophercloud/gophercloud/pagination"
     6  )
     7  
     8  // ListOptsBuilder allows extensions to add additional parameters to the
     9  // List request.
    10  type ListOptsBuilder interface {
    11  	ToProviderListQuery() (string, error)
    12  }
    13  
    14  // ListOpts allows the filtering and sorting of paginated collections through
    15  // the API. Filtering is achieved by passing in struct field values that map to
    16  // the Provider attributes you want to see returned.
    17  type ListOpts struct {
    18  	Fields []string `q:"fields"`
    19  }
    20  
    21  // ToProviderListQuery formats a ListOpts into a query string.
    22  func (opts ListOpts) ToProviderListQuery() (string, error) {
    23  	q, err := gophercloud.BuildQueryString(opts)
    24  	return q.String(), err
    25  }
    26  
    27  // List returns a Pager which allows you to iterate over a collection of
    28  // providers.
    29  //
    30  // Default policy settings return only those providers that are owned by
    31  // the project who submits the request, unless an admin user submits the request.
    32  func List(c *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    33  	url := rootURL(c)
    34  	if opts != nil {
    35  		query, err := opts.ToProviderListQuery()
    36  		if err != nil {
    37  			return pagination.Pager{Err: err}
    38  		}
    39  		url += query
    40  	}
    41  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
    42  		return ProviderPage{pagination.LinkedPageBase{PageResult: r}}
    43  	})
    44  }