github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/networking/v2/extensions/networkipavailabilities/requests.go (about) 1 package networkipavailabilities 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 ToNetworkIPAvailabilityListQuery() (string, error) 12 } 13 14 // ListOpts allows the filtering and sorting of paginated collections through 15 // the Neutron API. 16 type ListOpts struct { 17 // NetworkName allows to filter on the identifier of a network. 18 NetworkID string `q:"network_id"` 19 20 // NetworkName allows to filter on the name of a network. 21 NetworkName string `q:"network_name"` 22 23 // IPVersion allows to filter on the version of the IP protocol. 24 // You can use the well-known IP versions with the golangsdk.IPVersion type. 25 IPVersion string `q:"ip_version"` 26 27 // ProjectID allows to filter on the Identity project field. 28 ProjectID string `q:"project_id"` 29 30 // TenantID allows to filter on the Identity project field. 31 TenantID string `q:"tenant_id"` 32 } 33 34 // ToNetworkIPAvailabilityListQuery formats a ListOpts into a query string. 35 func (opts ListOpts) ToNetworkIPAvailabilityListQuery() (string, error) { 36 q, err := golangsdk.BuildQueryString(opts) 37 return q.String(), err 38 } 39 40 // List returns a Pager which allows you to iterate over a collection of 41 // networkipavailabilities. It accepts a ListOpts struct, which allows you to 42 // filter the returned collection for greater efficiency. 43 func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager { 44 url := listURL(c) 45 if opts != nil { 46 query, err := opts.ToNetworkIPAvailabilityListQuery() 47 if err != nil { 48 return pagination.Pager{Err: err} 49 } 50 url += query 51 } 52 return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page { 53 return NetworkIPAvailabilityPage{pagination.SinglePageBase(r)} 54 }) 55 } 56 57 // Get retrieves a specific NetworkIPAvailability based on its ID. 58 func Get(c *golangsdk.ServiceClient, id string) (r GetResult) { 59 _, r.Err = c.Get(getURL(c, id), &r.Body, nil) 60 return 61 }