Starting documentation and privatising unnecessary exports
diff --git a/openstack/networking/v2/apiversions/doc.go b/openstack/networking/v2/apiversions/doc.go
index 9ec7ea2..0208ee2 100644
--- a/openstack/networking/v2/apiversions/doc.go
+++ b/openstack/networking/v2/apiversions/doc.go
@@ -1,3 +1,4 @@
// Package apiversions provides information and interaction with the different
-// API versions for the Neutron OpenStack service.
+// API versions for the OpenStack Neutron service. This functionality is not
+// restricted to this particular version.
package apiversions
diff --git a/openstack/networking/v2/apiversions/requests.go b/openstack/networking/v2/apiversions/requests.go
index 570b9e8..b653f51 100644
--- a/openstack/networking/v2/apiversions/requests.go
+++ b/openstack/networking/v2/apiversions/requests.go
@@ -7,7 +7,7 @@
// ListVersions lists all the Neutron API versions available to end-users
func ListVersions(c *gophercloud.ServiceClient) pagination.Pager {
- return pagination.NewPager(c, APIVersionsURL(c), func(r pagination.LastHTTPResponse) pagination.Page {
+ return pagination.NewPager(c, apiVersionsURL(c), func(r pagination.LastHTTPResponse) pagination.Page {
return APIVersionPage{pagination.SinglePageBase(r)}
})
}
@@ -15,7 +15,7 @@
// ListVersionResources lists all of the different API resources for a particular
// API versions. Typical resources for Neutron might be: networks, subnets, etc.
func ListVersionResources(c *gophercloud.ServiceClient, v string) pagination.Pager {
- return pagination.NewPager(c, APIInfoURL(c, v), func(r pagination.LastHTTPResponse) pagination.Page {
+ return pagination.NewPager(c, apiInfoURL(c, v), func(r pagination.LastHTTPResponse) pagination.Page {
return APIVersionResourcePage{pagination.SinglePageBase(r)}
})
}
diff --git a/openstack/networking/v2/apiversions/results.go b/openstack/networking/v2/apiversions/results.go
index 0ab3b41..e13998d 100644
--- a/openstack/networking/v2/apiversions/results.go
+++ b/openstack/networking/v2/apiversions/results.go
@@ -18,7 +18,7 @@
pagination.SinglePageBase
}
-// IsEmpty checks whether the page is empty.
+// IsEmpty checks whether an APIVersionPage struct is empty.
func (r APIVersionPage) IsEmpty() (bool, error) {
is, err := ExtractAPIVersions(r)
if err != nil {
@@ -27,7 +27,7 @@
return len(is) == 0, nil
}
-// ExtractAPIVersion takes a collection page, extracts all of the elements,
+// ExtractAPIVersions takes a collection page, extracts all of the elements,
// and returns them a slice of APIVersion structs. It is effectively a cast.
func ExtractAPIVersions(page pagination.Page) ([]APIVersion, error) {
var resp struct {
@@ -49,10 +49,14 @@
Collection string `mapstructure:"collection" json:"collection"`
}
+// APIVersionResourcePage is a concrete type which embeds the common
+// SinglePageBase struct, and is used when traversing API versions collections.
type APIVersionResourcePage struct {
pagination.SinglePageBase
}
+// IsEmpty is a concrete function which indicates whether an
+// APIVersionResourcePage is empty or not.
func (r APIVersionResourcePage) IsEmpty() (bool, error) {
is, err := ExtractVersionResources(r)
if err != nil {
@@ -61,6 +65,10 @@
return len(is) == 0, nil
}
+// ExtractVersionResources accepts a Page struct, specifically a
+// APIVersionResourcePage struct, and extracts the elements into a slice of
+// APIVersionResource structs. In other words, the collection is mapped into
+// a relevant slice.
func ExtractVersionResources(page pagination.Page) ([]APIVersionResource, error) {
var resp struct {
APIVersionResources []APIVersionResource `mapstructure:"resources"`
diff --git a/openstack/networking/v2/apiversions/urls.go b/openstack/networking/v2/apiversions/urls.go
index e66434e..c43f991 100644
--- a/openstack/networking/v2/apiversions/urls.go
+++ b/openstack/networking/v2/apiversions/urls.go
@@ -6,10 +6,10 @@
"github.com/rackspace/gophercloud"
)
-func APIVersionsURL(c *gophercloud.ServiceClient) string {
+func apiVersionsURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL("")
}
-func APIInfoURL(c *gophercloud.ServiceClient, version string) string {
+func apiInfoURL(c *gophercloud.ServiceClient, version string) string {
return c.ServiceURL(strings.TrimRight(version, "/") + "/")
}
diff --git a/openstack/networking/v2/apiversions/urls_test.go b/openstack/networking/v2/apiversions/urls_test.go
index 383ba59..7dd069c 100644
--- a/openstack/networking/v2/apiversions/urls_test.go
+++ b/openstack/networking/v2/apiversions/urls_test.go
@@ -7,20 +7,20 @@
th "github.com/rackspace/gophercloud/testhelper"
)
-const Endpoint = "http://localhost:57909/"
+const endpoint = "http://localhost:57909/"
-func EndpointClient() *gophercloud.ServiceClient {
- return &gophercloud.ServiceClient{Endpoint: Endpoint}
+func endpointClient() *gophercloud.ServiceClient {
+ return &gophercloud.ServiceClient{Endpoint: endpoint}
}
func TestAPIVersionsURL(t *testing.T) {
- actual := APIVersionsURL(EndpointClient())
- expected := Endpoint
+ actual := apiVersionsURL(endpointClient())
+ expected := endpoint
th.AssertEquals(t, expected, actual)
}
func TestAPIInfoURL(t *testing.T) {
- actual := APIInfoURL(EndpointClient(), "v2.0")
- expected := Endpoint + "v2.0/"
+ actual := apiInfoURL(endpointClient(), "v2.0")
+ expected := endpoint + "v2.0/"
th.AssertEquals(t, expected, actual)
}