github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/blockstorage/extensions/services/requests.go (about)

     1  package services
     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 List
     9  // request.
    10  type ListOptsBuilder interface {
    11  	ToServiceListQuery() (string, error)
    12  }
    13  
    14  // ListOpts holds options for listing Services.
    15  type ListOpts struct {
    16  	// Filter the service list result by binary name of the service.
    17  	Binary string `q:"binary"`
    18  
    19  	// Filter the service list result by host name of the service.
    20  	Host string `q:"host"`
    21  }
    22  
    23  // ToServiceListQuery formats a ListOpts into a query string.
    24  func (opts ListOpts) ToServiceListQuery() (string, error) {
    25  	q, err := golangsdk.BuildQueryString(opts)
    26  	return q.String(), err
    27  }
    28  
    29  // List makes a request against the API to list services.
    30  func List(client *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    31  	url := listURL(client)
    32  	if opts != nil {
    33  		query, err := opts.ToServiceListQuery()
    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 ServicePage{pagination.SinglePageBase(r)}
    41  	})
    42  }