List index metadata (Go)
Gets information about the indexes associated with a specific table.
|
Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart. |
Result
Returns an unordered slice of IndexDescriptor structs that describe each index in the table.
Signature
Use the ListIndexes method, which belongs to the Table type.
func (t *Table) ListIndexes(
ctx context.Context,
opts ...options.ListIndexesOption
) ([]results.IndexDescriptor, 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 get index metadata for a table.
List index metadata
package main
import (
"context"
"encoding/json"
"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 an existing table
client := astra.NewClient()
database := client.Database(
"API_ENDPOINT",
options.API().SetToken("APPLICATION_TOKEN"),
)
table := database.Table("TABLE_NAME")
// List index metadata
indexes, err := table.ListIndexes(ctx)
if err != nil {
log.Fatal(err)
}
output, err := json.Marshal(indexes)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(output))
}
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.