Change identity endpoints and services.
diff --git a/openstack/identity/v3/services/requests.go b/openstack/identity/v3/services/requests.go
index 7bc4a82..af2ce54 100644
--- a/openstack/identity/v3/services/requests.go
+++ b/openstack/identity/v3/services/requests.go
@@ -6,6 +6,7 @@
"github.com/racker/perigee"
"github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack/utils"
+ "github.com/rackspace/gophercloud/pagination"
)
type response struct {
@@ -42,7 +43,7 @@
}
// List enumerates the services available to a specific user.
-func List(client *gophercloud.ServiceClient, opts ListOpts) gophercloud.Pager {
+func List(client *gophercloud.ServiceClient, opts ListOpts) pagination.Pager {
q := make(map[string]string)
if opts.ServiceType != "" {
q["type"] = opts.ServiceType
@@ -55,15 +56,11 @@
}
u := getListURL(client) + utils.BuildQuery(q)
- countPage := func(p gophercloud.Page) (int, error) {
- services, err := ExtractServices(p)
- if err != nil {
- return 0, err
- }
- return len(services), nil
+ createPage := func(r pagination.LastHTTPResponse) pagination.Page {
+ return ServicePage{pagination.LinkedPageBase(r)}
}
- return gophercloud.NewLinkedPager(client, u, countPage)
+ return pagination.NewLinkedPager(client, u, createPage)
}
// Get returns additional information about a service, given its ID.
diff --git a/openstack/identity/v3/services/requests_test.go b/openstack/identity/v3/services/requests_test.go
index 59cefe3..804f034 100644
--- a/openstack/identity/v3/services/requests_test.go
+++ b/openstack/identity/v3/services/requests_test.go
@@ -7,6 +7,7 @@
"testing"
"github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
"github.com/rackspace/gophercloud/testhelper"
)
@@ -99,7 +100,7 @@
client := serviceClient()
count := 0
- err := List(client, ListOpts{}).EachPage(func(page gophercloud.Page) (bool, error) {
+ err := List(client, ListOpts{}).EachPage(func(page pagination.Page) (bool, error) {
count++
actual, err := ExtractServices(page)
if err != nil {
diff --git a/openstack/identity/v3/services/results.go b/openstack/identity/v3/services/results.go
index 537ea2e..cccea8e 100644
--- a/openstack/identity/v3/services/results.go
+++ b/openstack/identity/v3/services/results.go
@@ -1,7 +1,7 @@
package services
import (
- "github.com/rackspace/gophercloud"
+ "github.com/rackspace/gophercloud/pagination"
"github.com/mitchellh/mapstructure"
)
@@ -14,12 +14,26 @@
Type string `json:"type"`
}
+// ServicePage is a single page of Service results.
+type ServicePage struct {
+ pagination.LinkedPageBase
+}
+
+// IsEmpty returns true if the page contains no results.
+func (p ServicePage) IsEmpty() (bool, error) {
+ services, err := ExtractServices(p)
+ if err != nil {
+ return true, err
+ }
+ return len(services) == 0, nil
+}
+
// ExtractServices extracts a slice of Services from a Collection acquired from List.
-func ExtractServices(page gophercloud.Page) ([]Service, error) {
+func ExtractServices(page pagination.Page) ([]Service, error) {
var response struct {
Services []Service `mapstructure:"services"`
}
- err := mapstructure.Decode(page.(gophercloud.LinkedPage).Body, &response)
+ err := mapstructure.Decode(page.(ServicePage).Body, &response)
return response.Services, err
}