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)
}
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)
}