diff --git a/openstack/identity/v3/endpoints/requests.go b/openstack/identity/v3/endpoints/requests.go index f5f8b0c4..7bdb7cef 100644 --- a/openstack/identity/v3/endpoints/requests.go +++ b/openstack/identity/v3/endpoints/requests.go @@ -1,8 +1,6 @@ package endpoints import ( - "strconv" - "github.com/racker/perigee" "github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud/pagination" @@ -71,33 +69,24 @@ func Create(client *gophercloud.ServiceClient, opts EndpointOpts) CreateResult { // ListOpts allows finer control over the endpoints returned by a List call. // All fields are optional. type ListOpts struct { - Availability gophercloud.Availability - ServiceID string - Page int - PerPage int + Availability gophercloud.Availability `q:"interface"` + ServiceID string `q:"service_id"` + Page int `q:"page"` + PerPage int `q:"per_page"` } // List enumerates endpoints in a paginated collection, optionally filtered by ListOpts criteria. func List(client *gophercloud.ServiceClient, opts ListOpts) pagination.Pager { - q := make(map[string]string) - if opts.Availability != "" { - q["interface"] = string(opts.Availability) - } - if opts.ServiceID != "" { - q["service_id"] = opts.ServiceID + u := listURL(client) + q, err := gophercloud.BuildQueryString(opts) + if err != nil { + return pagination.Pager{Err: err} } - if opts.Page != 0 { - q["page"] = strconv.Itoa(opts.Page) - } - if opts.PerPage != 0 { - q["per_page"] = strconv.Itoa(opts.Page) - } - + u += q.String() createPage := func(r pagination.PageResult) pagination.Page { return EndpointPage{pagination.LinkedPageBase{PageResult: r}} } - u := listURL(client) + gophercloud.BuildQuery(q) return pagination.NewPager(client, u, createPage) } diff --git a/openstack/identity/v3/services/requests.go b/openstack/identity/v3/services/requests.go index bf027e81..1d9aaa87 100644 --- a/openstack/identity/v3/services/requests.go +++ b/openstack/identity/v3/services/requests.go @@ -1,8 +1,6 @@ package services import ( - "strconv" - "github.com/racker/perigee" "github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud/pagination" @@ -32,25 +30,19 @@ func Create(client *gophercloud.ServiceClient, serviceType string) CreateResult // ListOpts allows you to query the List method. type ListOpts struct { - ServiceType string - PerPage int - Page int + ServiceType string `q:"type"` + PerPage int `q:"perPage"` + Page int `q:"page"` } // List enumerates the services available to a specific user. func List(client *gophercloud.ServiceClient, opts ListOpts) pagination.Pager { - q := make(map[string]string) - if opts.ServiceType != "" { - q["type"] = opts.ServiceType - } - if opts.Page != 0 { - q["page"] = strconv.Itoa(opts.Page) + u := listURL(client) + q, err := gophercloud.BuildQueryString(opts) + if err != nil { + return pagination.Pager{Err: err} } - if opts.PerPage != 0 { - q["perPage"] = strconv.Itoa(opts.PerPage) - } - u := listURL(client) + gophercloud.BuildQuery(q) - + u += q.String() createPage := func(r pagination.PageResult) pagination.Page { return ServicePage{pagination.LinkedPageBase{PageResult: r}} } diff --git a/util.go b/util.go index 7f5ead7d..101fd395 100644 --- a/util.go +++ b/util.go @@ -37,17 +37,3 @@ func NormalizeURL(url string) string { } return url } - -// BuildQuery constructs the query section of a URI from a map. -func BuildQuery(params map[string]string) string { - if len(params) == 0 { - return "" - } - - query := "?" - for k, v := range params { - query += k + "=" + v + "&" - } - query = query[:len(query)-1] - return query -}