import ( "github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud/openstack" ) // Create a new authentication options struct. ao := gophercloud.AuthOptions{ IdentityEndpoint: "https://identity.example.com/v3", Username: "my-username", Password: "my-password", DomainName: "my-domain", } // Create a new provider client. provider, err := openstack.AuthenticatedClient(ao) if err != nil { panic(err) } // Create a new ServiceClient using the provider. sc, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{ Region: "RegionOne", }) if err != nil { panic(err) } // Set the headers using AuthenticatedHeaders method. headers := map[string]string{} sc.AuthenticatedHeaders(headers) // Make GET request to list all servers. resp, err := sc.Get("servers", nil, &gophercloud.RequestOpts{ Headers: headers, }) if err != nil { panic(err) }
import ( "github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud/openstack" ) // Create a new authentication options struct. ao := gophercloud.AuthOptions{ IdentityEndpoint: "https://identity.example.com/v3", Username: "my-username", Password: "my-password", DomainName: "my-domain", } // Create a new provider client. provider, err := openstack.AuthenticatedClient(ao) if err != nil { panic(err) } // Create a new ServiceClient using the provider. sc, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{ Region: "RegionOne", }) if err != nil { panic(err) } // Set the headers using AuthenticatedHeaders method. headers := map[string]string{} sc.AuthenticatedHeaders(headers) // Set the X-Subject-Token header if available. if token := headers[gophercloud.XAuthToken]; token != "" { headers[gophercloud.XSubjectToken] = token } // Make GET request to list all servers. resp, err := sc.Get("servers", nil, &gophercloud.RequestOpts{ Headers: headers, }) if err != nil { panic(err) }Brief Description: The above code examples show how to use AuthenticatedHeaders method to set headers before making HTTP requests to OpenStack API servers. The first example sets the X-Auth-Token header, whereas the second example additionally sets the X-Subject-Token header if available.