import ( "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack" ) func main() { // Get credentials authOpts, err := openstack.AuthOptionsFromEnv() if err != nil { panic(err) } // Create a new client provider, err := openstack.AuthenticatedClient(authOpts) if err != nil { panic(err) } // Create a compute service client client, err := openstack.NewComputeV2(provider, gophercloud.EndpointOpts{ Region: "RegionOne", }) if err != nil { panic(err) } // Use the client to list servers servers, err := servers.List(client, nil).AllPages() if err != nil { panic(err) } // Print server names for _, server := range servers { fmt.Println(server.Name) } }
import ( "github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud/openstack" ) func main() { // Get credentials authOpts, err := openstack.AuthOptionsFromEnv() if err != nil { panic(err) } // Create a new client provider, err := openstack.AuthenticatedClient(authOpts) if err != nil { panic(err) } // Create a block storage service client client, err := openstack.NewBlockStorageV3(provider, gophercloud.EndpointOpts{ Region: "RegionOne", }) if err != nil { panic(err) } // Use the client to list volumes volumes, err := volumes.List(client, nil).AllPages() if err != nil { panic(err) } // Print volume names for _, volume := range volumes { fmt.Println(volume.Name) } }This example shows how to use the ServiceClient to create a block storage service client and list volumes. Package Library: github.com/gophercloud/gophercloud.