List keyspaces (Go)
Lists all keyspaces in a database.
|
You need an application token with permission to interact with the target database, such as the Database Administrator role. For more information, see Get endpoint and token. |
Result
Returns the keyspace names as a slice of strings.
Signature
Use the ListKeyspaces method, which belongs to the AstraDatabaseAdmin type.
func (a *AstraDatabaseAdmin) ListKeyspaces(
ctx context.Context,
opts ...options.ListKeyspacesOption
) error
Parameters
| Name | Type | Summary |
|---|---|---|
|
|
The context for the operation. |
|
Optional.
A builder to generate options for this operation.
See Methods of the |
| Method | Summary |
|---|---|
|
Optional. General API options for this operation, including the timeout. |
Examples
The following examples demonstrate how to list keyspaces.
List keyspaces
package main
import (
"context"
"fmt"
"log"
"github.com/datastax/astra-db-go/v2/astra"
"github.com/datastax/astra-db-go/v2/astra/options"
)
func main() {
ctx := context.Background()
// Get a database
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
// Get an admin object
admin, err := database.DatabaseAdmin()
if err != nil {
log.Fatal(err)
}
// List keyspaces
keyspaces, err := admin.ListKeyspaces(ctx)
if err != nil {
log.Fatal(err)
}
fmt.Println(keyspaces)
}
Errors
For a full list of Data API error codes and their corresponding messages, see Data API errors and error codes.
For more information about how the client handles underlying Data API errors, see Go client error handling.
Client reference
For more information, see the client reference.