rackspace/gophercloud — pull request #181 by jrperritt (2014-08-19 21:46:51+00:00)
Title: Os identity endpoint fix

Related to #179

Also here: https://groups.google.com/forum/#!topic/gophercloud-dev/eV3zPG0KpwU

Currently in branch v0.2.0, users have to write their own logic for finding Identity endpoints. This PR provides a "NewClient" method in a new file called client.go. It also adds a "v2" directory for versioning. The PR looks large, and it is, but it's mostly small changes to several files. The important code is in the opestack/identity/v2/client.go file. It enables a user to provide a service type, service name, region, and URL type as parameters. Those parameters along with the AuthOptions are used to return an unspecific "Client", which can then be used to create a more specific service "Client". For example,

ao, err := utils.AuthOptions()
c, err := ao.NewClient(identity.EndpointOpts{
Type: "compute",
Name: "nova",
})
serversClient := servers.NewClient(c.Endpoint, c.Authority, c.Options)

Some notes on the EndpointOpts:
Name is only used if provided.
URLType defaults to "public".
If Region is set, it is used. Otherwise, it uses the OS_REGION_NAME environment variable.