github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/networking/v2/extensions/networkipavailabilities/requests.go (about)

     1  package networkipavailabilities
     2  
     3  import (
     4  	"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  	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  	if err != nil {
    38  		return "", err
    39  	}
    40  	return q.String(), err
    41  }
    42  
    43  // List returns a Pager which allows you to iterate over a collection of
    44  // networkipavailabilities. It accepts a ListOpts struct, which allows you to
    45  // filter the returned collection for greater efficiency.
    46  func List(c *golangsdk.ServiceClient, opts ListOptsBuilder) pagination.Pager {
    47  	url := listURL(c)
    48  	if opts != nil {
    49  		query, err := opts.ToNetworkIPAvailabilityListQuery()
    50  		if err != nil {
    51  			return pagination.Pager{Err: err}
    52  		}
    53  		url += query
    54  	}
    55  	return pagination.NewPager(c, url, func(r pagination.PageResult) pagination.Page {
    56  		return NetworkIPAvailabilityPage{pagination.SinglePageBase(r)}
    57  	})
    58  }
    59  
    60  // Get retrieves a specific NetworkIPAvailability based on its ID.
    61  func Get(c *golangsdk.ServiceClient, id string) (r GetResult) {
    62  	_, r.Err = c.Get(getURL(c, id), &r.Body, nil)
    63  	return
    64  }