remove need for Pager.PageType
diff --git a/openstack/blockstorage/v1/volumes/requests.go b/openstack/blockstorage/v1/volumes/requests.go
index af18e7e..e67ba10 100644
--- a/openstack/blockstorage/v1/volumes/requests.go
+++ b/openstack/blockstorage/v1/volumes/requests.go
@@ -152,9 +152,8 @@
createPage := func(r pagination.PageResult) pagination.Page {
return ListResult{pagination.SinglePageBase(r)}
}
- p := pagination.NewPager(client, url, createPage)
- p.PageType = ListResult{}
- return p
+
+ return pagination.NewPager(client, url, createPage)
}
// UpdateOptsBuilder allows extensions to add additional parameters to the
diff --git a/openstack/compute/v2/servers/requests.go b/openstack/compute/v2/servers/requests.go
index f8c2dc3..b7c1611 100644
--- a/openstack/compute/v2/servers/requests.go
+++ b/openstack/compute/v2/servers/requests.go
@@ -73,9 +73,7 @@
return ServerPage{pagination.LinkedPageBase{PageResult: r}}
}
- p := pagination.NewPager(client, url, createPageFn)
- p.PageType = ServerPage{}
- return p
+ return pagination.NewPager(client, url, createPageFn)
}
// CreateOptsBuilder describes struct types that can be accepted by the Create call.
diff --git a/openstack/objectstorage/v1/containers/requests.go b/openstack/objectstorage/v1/containers/requests.go
index c282255..a29d7da 100644
--- a/openstack/objectstorage/v1/containers/requests.go
+++ b/openstack/objectstorage/v1/containers/requests.go
@@ -58,7 +58,6 @@
}
pager := pagination.NewPager(c, url, createPage)
- pager.PageType = ContainerPage{}
pager.Headers = headers
return pager
}
diff --git a/pagination/linked_test.go b/pagination/linked_test.go
index e2ba7e5..1ac0f73 100644
--- a/pagination/linked_test.go
+++ b/pagination/linked_test.go
@@ -110,7 +110,6 @@
pager := createLinked(t)
defer testhelper.TeardownHTTP()
- pager.PageType = LinkedPageResult{}
page, err := pager.AllPages()
testhelper.AssertNoErr(t, err)
diff --git a/pagination/marker_test.go b/pagination/marker_test.go
index f003177..f4d55be 100644
--- a/pagination/marker_test.go
+++ b/pagination/marker_test.go
@@ -116,7 +116,6 @@
pager := createMarkerPaged(t)
defer testhelper.TeardownHTTP()
- pager.PageType = MarkerPageResult{}
page, err := pager.AllPages()
testhelper.AssertNoErr(t, err)
diff --git a/pagination/pager.go b/pagination/pager.go
index 817b806..ea47c69 100644
--- a/pagination/pager.go
+++ b/pagination/pager.go
@@ -46,11 +46,6 @@
// Headers supplies additional HTTP headers to populate on each paged request.
Headers map[string]string
-
- // PageType is the type of `Page` the `Extract*` function expects back. This is
- // needed because a type assertion occurs in each `Extract*` function, and it will
- // fail if the `Page` doesn't have the expected type.
- PageType Page
}
// NewPager constructs a manually-configured pager.
@@ -129,10 +124,6 @@
// AllPages returns all the pages from a `List` operation in a single page,
// allowing the user to retrieve all the pages at once.
func (p Pager) AllPages() (Page, error) {
- // Having a value of `nil` for `p.PageType` will cause a run-time error.
- if p.PageType == nil {
- return nil, fmt.Errorf("Pager field PageType must be set to successfully call pagination.AllPages method.")
- }
// pagesSlice holds all the pages until they get converted into as Page Body.
var pagesSlice []interface{}
// body will contain the final concatenated Page body.
@@ -143,6 +134,9 @@
if err != nil {
return nil, err
}
+ // Store the page type so we can use reflection to create a new mega-page of
+ // that type.
+ pageType := reflect.TypeOf(testPage)
// Switch on the page body type. Recognized types are `map[string]interface{}`,
// `[]byte`, and `[]interface{}`.
@@ -210,11 +204,11 @@
}
// Each `Extract*` function is expecting a specific type of page coming back,
- // otherwise the type assertion in those functions will fail. PageType is needed
+ // otherwise the type assertion in those functions will fail. pageType is needed
// to create a type in this method that has the same type that the `Extract*`
// function is expecting and set the Body of that object to the concatenated
// pages.
- page := reflect.New(reflect.TypeOf(p.PageType))
+ page := reflect.New(pageType)
// Set the page body to be the concatenated pages.
page.Elem().FieldByName("Body").Set(body)
// Set any additional headers that were pass along. The `objectstorage` pacakge,
diff --git a/pagination/single_test.go b/pagination/single_test.go
index 7c07dfe..4af0fee 100644
--- a/pagination/single_test.go
+++ b/pagination/single_test.go
@@ -74,7 +74,6 @@
pager := setupSinglePaged()
defer testhelper.TeardownHTTP()
- pager.PageType = SinglePageResult{}
page, err := pager.AllPages()
testhelper.AssertNoErr(t, err)