github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/iec/v1/sites/requests.go (about)

     1  package sites
     2  
     3  import (
     4  	"github.com/huaweicloud/golangsdk"
     5  	"github.com/huaweicloud/golangsdk/pagination"
     6  )
     7  
     8  //ListSiteOptsBuilder list sites builder
     9  type ListSiteOptsBuilder interface {
    10  	ToListSiteQuery() (string, error)
    11  }
    12  
    13  // ListSiteOpts to list site
    14  type ListSiteOpts struct {
    15  	//Limit query limit
    16  	Limit string `q:"limit"`
    17  
    18  	//Offset query begin index
    19  	Offset string `q:"offset"`
    20  
    21  	//id query by id
    22  	ID string `q:"id"`
    23  
    24  	//Area query by area
    25  	Area string `q:"area"`
    26  
    27  	//Province query by province
    28  	Province string `q:"province"`
    29  
    30  	//City query by city
    31  	City string `q:"city"`
    32  
    33  	//Operator query by operator
    34  	Operator string `q:"operator"`
    35  }
    36  
    37  // ToListSiteQuery converts ListSiteOpts structures to query string
    38  func (opts ListSiteOpts) ToListSiteQuery() (string, error) {
    39  	q, err := golangsdk.BuildQueryString(opts)
    40  	return q.String(), err
    41  }
    42  
    43  // List returns a Pager which allows you to iterate over a collection of
    44  // sites. It accepts a ListOpts struct, which allows you to filter and sort
    45  // the returned collection for greater efficiency.
    46  func List(client *golangsdk.ServiceClient, opts ListSiteOptsBuilder) pagination.Pager {
    47  	url := ListURL(client)
    48  	if opts != nil {
    49  		query, err := opts.ToListSiteQuery()
    50  		if err != nil {
    51  			return pagination.Pager{Err: err}
    52  		}
    53  		url += query
    54  	}
    55  	return pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
    56  		return SitePage{pagination.LinkedPageBase{PageResult: r}}
    57  	})
    58  }