import ( "github.com/rackspace/gophercloud" "github.com/rackspace/gophercloud/openstack/compute/v2/servers" ) opts := gophercloud.AuthOptions{ IdentityEndpoint: "https://identity.example.com/v3/", Username: "username", Password: "password", TenantName: "tenantname", } provider, err := gophercloud.Authenticate(opts) if err != nil { // handle authentication error } client, err := gophercloud.NewServiceClient(provider, servers.ServiceType) if err != nil { // handle client creation error }
opts := servers.ListOpts{ Limit: 10, } pager := servers.List(client, opts) err := pager.EachPage(func(page pagination.Page) (bool, error) { serverList, err := servers.ExtractServers(page) if err != nil { // handle server extraction error return false, err } for _, server := range serverList { // handle individual server data } return true, nil }) if err != nil { // handle pagination error }In this example, we are using the List method of the servers package to make a request to list servers. The ListOpts struct allows us to specify query parameters to filter the results. We then use the pager returned by the List method to iterate through the pages of results. The ExtractServers function is used to extract server data from the page, which we can then handle however we need to.