Starting documentation and privatising unnecessary exports
diff --git a/openstack/networking/v2/extensions/doc.go b/openstack/networking/v2/extensions/doc.go
index aeec0fa..7942c39 100644
--- a/openstack/networking/v2/extensions/doc.go
+++ b/openstack/networking/v2/extensions/doc.go
@@ -1 +1,15 @@
+// Package extensions provides information and interaction with the different
+// extensions available for the OpenStack Neutron service.
+//
+// The purpose of Networking API v2.0 extensions is to:
+//
+// - Introduce new features in the API without requiring a version change.
+// - Introduce vendor-specific niche functionality.
+// - Act as a proving ground for experimental functionalities that might be
+// included in a future version of the API.
+//
+// Extensions usually have tags that prevent conflicts with other extensions
+// that define attributes or resources with the same names, and with core
+// resources and attributes. Because an extension might not be supported by all
+// plug-ins, its availability varies with deployments and the specific plug-in.
package extensions
diff --git a/openstack/networking/v2/extensions/requests.go b/openstack/networking/v2/extensions/requests.go
index 7120490..d24108e 100644
--- a/openstack/networking/v2/extensions/requests.go
+++ b/openstack/networking/v2/extensions/requests.go
@@ -6,9 +6,11 @@
"github.com/rackspace/gophercloud/pagination"
)
-func Get(c *gophercloud.ServiceClient, name string) (*Extension, error) {
+// Get retrieves information for a specific extension using its alias. If no
+// extension exists with this alias, an error will be returned.
+func Get(c *gophercloud.ServiceClient, alias string) (*Extension, error) {
var ext Extension
- _, err := perigee.Request("GET", ExtensionURL(c, name), perigee.Options{
+ _, err := perigee.Request("GET", extensionURL(c, alias), perigee.Options{
MoreHeaders: c.Provider.AuthenticatedHeaders(),
Results: &struct {
Extension *Extension `json:"extension"`
@@ -22,8 +24,10 @@
return &ext, nil
}
+// List returns a Pager which allows you to iterate over the full collection of
+// extensions. It does not accept query parameters.
func List(c *gophercloud.ServiceClient) pagination.Pager {
- return pagination.NewPager(c, ListExtensionURL(c), func(r pagination.LastHTTPResponse) pagination.Page {
+ return pagination.NewPager(c, listExtensionURL(c), func(r pagination.LastHTTPResponse) pagination.Page {
return ExtensionPage{pagination.SinglePageBase(r)}
})
}
diff --git a/openstack/networking/v2/extensions/results.go b/openstack/networking/v2/extensions/results.go
index c67bd01..42e7fc3 100644
--- a/openstack/networking/v2/extensions/results.go
+++ b/openstack/networking/v2/extensions/results.go
@@ -5,6 +5,7 @@
"github.com/rackspace/gophercloud/pagination"
)
+// Extension is a struct that represents a Neutron extension.
type Extension struct {
Updated string `json:"updated"`
Name string `json:"name"`
@@ -14,10 +15,13 @@
Description string `json:"description"`
}
+// ExtensionPage is the page returned by a pager when traversing over a
+// collection of extensions.
type ExtensionPage struct {
pagination.SinglePageBase
}
+// IsEmpty checks whether an ExtensionPage struct is empty.
func (r ExtensionPage) IsEmpty() (bool, error) {
is, err := ExtractExtensions(r)
if err != nil {
@@ -26,6 +30,9 @@
return len(is) == 0, nil
}
+// ExtractExtensions accepts a Page struct, specifically an ExtensionPage
+// struct, and extracts the elements into a slice of Extension structs. In other
+// words, a generic collection is mapped into a relevant slice.
func ExtractExtensions(page pagination.Page) ([]Extension, error) {
var resp struct {
Extensions []Extension `mapstructure:"extensions"`
diff --git a/openstack/networking/v2/extensions/urls.go b/openstack/networking/v2/extensions/urls.go
index 608b25f..e31e76c 100644
--- a/openstack/networking/v2/extensions/urls.go
+++ b/openstack/networking/v2/extensions/urls.go
@@ -2,12 +2,12 @@
import "github.com/rackspace/gophercloud"
-const Version = "v2.0"
+const version = "v2.0"
-func ExtensionURL(c *gophercloud.ServiceClient, name string) string {
- return c.ServiceURL(Version, "extensions", name)
+func extensionURL(c *gophercloud.ServiceClient, name string) string {
+ return c.ServiceURL(version, "extensions", name)
}
-func ListExtensionURL(c *gophercloud.ServiceClient) string {
- return c.ServiceURL(Version, "extensions")
+func listExtensionURL(c *gophercloud.ServiceClient) string {
+ return c.ServiceURL(version, "extensions")
}
diff --git a/openstack/networking/v2/extensions/urls_test.go b/openstack/networking/v2/extensions/urls_test.go
index 34731cd..2a1e6a1 100644
--- a/openstack/networking/v2/extensions/urls_test.go
+++ b/openstack/networking/v2/extensions/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 TestExtensionURL(t *testing.T) {
- actual := ExtensionURL(EndpointClient(), "agent")
- expected := Endpoint + "v2.0/extensions/agent"
+ actual := extensionURL(endpointClient(), "agent")
+ expected := endpoint + "v2.0/extensions/agent"
th.AssertEquals(t, expected, actual)
}
func TestListExtensionURL(t *testing.T) {
- actual := ListExtensionURL(EndpointClient())
- expected := Endpoint + "v2.0/extensions"
+ actual := listExtensionURL(endpointClient())
+ expected := endpoint + "v2.0/extensions"
th.AssertEquals(t, expected, actual)
}