add ApplyDefaults method for EndpointOpts
diff --git a/acceptance/openstack/client_test.go b/acceptance/openstack/client_test.go
index 9b12337..52c0cf5 100644
--- a/acceptance/openstack/client_test.go
+++ b/acceptance/openstack/client_test.go
@@ -6,6 +6,7 @@
"os"
"testing"
+ "github.com/rackspace/gophercloud"
"github.com/rackspace/gophercloud/openstack"
"github.com/rackspace/gophercloud/openstack/utils"
)
@@ -29,7 +30,9 @@
t.Logf("Client successfully acquired a token: %v", client.TokenID)
// Find the storage service in the service catalog.
- storage, err := openstack.NewStorageV1(client, os.Getenv("OS_REGION_NAME"))
+ storage, err := openstack.NewStorageV1(client, gophercloud.EndpointOpts{
+ Region: os.Getenv("OS_REGION_NAME"),
+ })
if err != nil {
t.Errorf("Unable to locate a storage service: %v", err)
} else {
diff --git a/endpoint_search.go b/endpoint_search.go
index 7c80dea..16e170d 100644
--- a/endpoint_search.go
+++ b/endpoint_search.go
@@ -49,3 +49,13 @@
// EndpointLocator is a function that describes how to locate a single endpoint from a service catalog for a specific ProviderClient.
// It should be set during ProviderClient authentication and used to discover related ServiceClients.
type EndpointLocator func(EndpointOpts) (string, error)
+
+// ApplyDefaults sets EndpointOpts fields if not already set. Currently, EndpointOpts.Availability defaults to the public endpoint.
+func (eo *EndpointOpts) ApplyDefaults(t string) {
+ if eo.Type == "" {
+ eo.Type = t
+ }
+ if eo.Availability == "" {
+ eo.Availability = AvailabilityPublic
+ }
+}
diff --git a/openstack/client.go b/openstack/client.go
index 9ebdd65..7279bca 100644
--- a/openstack/client.go
+++ b/openstack/client.go
@@ -288,8 +288,9 @@
}
// NewStorageV1 creates a ServiceClient that may be used with the v1 object storage package.
-func NewStorageV1(client *gophercloud.ProviderClient, region string) (*gophercloud.ServiceClient, error) {
- url, err := client.EndpointLocator(gophercloud.EndpointOpts{Type: "object-store", Name: "swift"})
+func NewStorageV1(client *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) (*gophercloud.ServiceClient, error) {
+ eo.ApplyDefaults("object-store")
+ url, err := client.EndpointLocator(eo)
if err != nil {
return nil, err
}