Skip to content
This repository was archived by the owner on Aug 1, 2023. It is now read-only.

Commit da56de6

Browse files
committed
Merge pull request #284 from jrperritt/remove-BuildQuery
update functions to use BuildQueryString instead of BuildQuery
2 parents 57847d7 + 1980344 commit da56de6

File tree

3 files changed

+17
-50
lines changed

3 files changed

+17
-50
lines changed

openstack/identity/v3/endpoints/requests.go

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package endpoints
22

33
import (
4-
"strconv"
5-
64
"github.com/racker/perigee"
75
"github.com/rackspace/gophercloud"
86
"github.com/rackspace/gophercloud/pagination"
@@ -71,33 +69,24 @@ func Create(client *gophercloud.ServiceClient, opts EndpointOpts) CreateResult {
7169
// ListOpts allows finer control over the endpoints returned by a List call.
7270
// All fields are optional.
7371
type ListOpts struct {
74-
Availability gophercloud.Availability
75-
ServiceID string
76-
Page int
77-
PerPage int
72+
Availability gophercloud.Availability `q:"interface"`
73+
ServiceID string `q:"service_id"`
74+
Page int `q:"page"`
75+
PerPage int `q:"per_page"`
7876
}
7977

8078
// List enumerates endpoints in a paginated collection, optionally filtered by ListOpts criteria.
8179
func List(client *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
82-
q := make(map[string]string)
83-
if opts.Availability != "" {
84-
q["interface"] = string(opts.Availability)
85-
}
86-
if opts.ServiceID != "" {
87-
q["service_id"] = opts.ServiceID
80+
u := listURL(client)
81+
q, err := gophercloud.BuildQueryString(opts)
82+
if err != nil {
83+
return pagination.Pager{Err: err}
8884
}
89-
if opts.Page != 0 {
90-
q["page"] = strconv.Itoa(opts.Page)
91-
}
92-
if opts.PerPage != 0 {
93-
q["per_page"] = strconv.Itoa(opts.Page)
94-
}
95-
85+
u += q.String()
9686
createPage := func(r pagination.PageResult) pagination.Page {
9787
return EndpointPage{pagination.LinkedPageBase{PageResult: r}}
9888
}
9989

100-
u := listURL(client) + gophercloud.BuildQuery(q)
10190
return pagination.NewPager(client, u, createPage)
10291
}
10392

openstack/identity/v3/services/requests.go

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package services
22

33
import (
4-
"strconv"
5-
64
"github.com/racker/perigee"
75
"github.com/rackspace/gophercloud"
86
"github.com/rackspace/gophercloud/pagination"
@@ -32,25 +30,19 @@ func Create(client *gophercloud.ServiceClient, serviceType string) CreateResult
3230

3331
// ListOpts allows you to query the List method.
3432
type ListOpts struct {
35-
ServiceType string
36-
PerPage int
37-
Page int
33+
ServiceType string `q:"type"`
34+
PerPage int `q:"perPage"`
35+
Page int `q:"page"`
3836
}
3937

4038
// List enumerates the services available to a specific user.
4139
func List(client *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
42-
q := make(map[string]string)
43-
if opts.ServiceType != "" {
44-
q["type"] = opts.ServiceType
45-
}
46-
if opts.Page != 0 {
47-
q["page"] = strconv.Itoa(opts.Page)
40+
u := listURL(client)
41+
q, err := gophercloud.BuildQueryString(opts)
42+
if err != nil {
43+
return pagination.Pager{Err: err}
4844
}
49-
if opts.PerPage != 0 {
50-
q["perPage"] = strconv.Itoa(opts.PerPage)
51-
}
52-
u := listURL(client) + gophercloud.BuildQuery(q)
53-
45+
u += q.String()
5446
createPage := func(r pagination.PageResult) pagination.Page {
5547
return ServicePage{pagination.LinkedPageBase{PageResult: r}}
5648
}

util.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,3 @@ func NormalizeURL(url string) string {
3737
}
3838
return url
3939
}
40-
41-
// BuildQuery constructs the query section of a URI from a map.
42-
func BuildQuery(params map[string]string) string {
43-
if len(params) == 0 {
44-
return ""
45-
}
46-
47-
query := "?"
48-
for k, v := range params {
49-
query += k + "=" + v + "&"
50-
}
51-
query = query[:len(query)-1]
52-
return query
53-
}

0 commit comments

Comments
 (0)