rackspace / gophercloud

A Go SDK for OpenStack. IN FEATURE FREEZE. See Issue #592
http://gophercloud.io
Other
456 stars 180 forks source link

Gophercloud.io examples are misleading #541

Open kaustavha opened 8 years ago

kaustavha commented 8 years ago

The example documentation on http://gophercloud.io/docs/identity/v2/ is out of date.

Example:


package main
import (
    "github.com/rackspace/gophercloud"
    "github.com/rackspace/gophercloud/openstack"
    "github.com/rackspace/gophercloud/openstack/identity/v2/tokens"
    "fmt"
)

func main() {
    var authOpts = gophercloud.AuthOptions{
        IdentityEndpoint: "https://identity.api.rackspacecloud.com/v2.0",
        Username: "cmdemo",
        Password: "xxx",
    }

    var provider, err1 = openstack.AuthenticatedClient(authOpts)
    var client = openstack.NewIdentityV2(provider)

    var opts = tokens.AuthOptions{
        IdentityEndpoint: "https://identity.api.rackspacecloud.com/v2.0",
        Username: "cmdemo",
        Password: "xxx",
    }

    var token, err3 = tokens.Create(client, opts).Extract()
    fmt.Println(token)
}

This results in the following sequence of errors:

# command-line-arguments
./keystone-client3.go:22: unknown "github.com/rackspace/gophercloud/openstack/identity/v2/tokens".AuthOptions field 'IdentityEndpoint' in struct literal
./keystone-client3.go:23: unknown "github.com/rackspace/gophercloud/openstack/identity/v2/tokens".AuthOptions field 'Username' in struct literal
./keystone-client3.go:24: unknown "github.com/rackspace/gophercloud/openstack/identity/v2/tokens".AuthOptions field 'Password' in struct literal
./keystone-client3.go:27: "github.com/rackspace/gophercloud/openstack/identity/v2/tokens".Create(client, opts).Extract undefined (type "github.com/rackspace/gophercloud/openstack/identity/v2/tokens".CreateResult has no field or method Extract)
codevulture commented 8 years ago

Hi,

You can use the code below by the time it is being resolved.

package main
import (
    "github.com/rackspace/gophercloud"
    "github.com/rackspace/gophercloud/openstack"
    "github.com/rackspace/gophercloud/openstack/identity/v2/tokens"
    "fmt"
)

func main() {
    var authOpts = gophercloud.AuthOptions{
        IdentityEndpoint: "https://identity.api.rackspacecloud.com/v2.0",
        Username: "cmdemo",
        Password: "xxx",
    }

var provider, _ = openstack.AuthenticatedClient(authOpts)
var client = openstack.NewIdentityV2(provider)

var opts = tokens.AuthOptions{
    authOpts,
}

var token, _ = tokens.Create(client, opts).ExtractToken()
fmt.Println(token)
}