ListVectorBuckets lists all vector buckets in your Alibaba Cloud account. The Go SDK V2 exposes this operation through a paginator, so results are retrieved page by page regardless of how many buckets exist.
Permissions
An Alibaba Cloud account has all permissions by default. By default, Resource Access Management (RAM) users or RAM roles have no permissions. The Alibaba Cloud account owner or an administrator must grant permissions using a RAM policy or a bucket policy.
| API | Action | Description |
|---|---|---|
| ListVectorBuckets | oss:ListVectorBuckets | Lists vector buckets. |
Method definition
func (c *VectorsClient) NewListVectorBucketsPaginator(params *ListVectorBucketsRequest, optFns ...func(*Options)) *ListVectorBucketsPaginatorRequest parameters
| Parameter | Type | Description |
|---|---|---|
| params | *ListVectorBucketsRequest | The request parameters. For details, see ListVectorBucketsRequest. |
| optFns | ...func(*Options) | Optional. Interface-level configuration parameters. For details, see Options. |
Return values
| Parameter | Type | Description |
|---|---|---|
| result | *ListVectorBucketsPaginator | A paginator for iterating through the list of vector buckets. Call HasNext() to check whether more pages are available, then call NextPage() to retrieve each page. For details, see ListVectorBucketsPaginator. |
Each page contains a slice of bucket entries. Each entry exposes the following fields:
| Field | Type | Description |
|---|---|---|
Name | *string | The name of the vector bucket. |
ResourceGroupId | *string | The ID of the resource group the bucket belongs to. |
Location | *string | The region where the bucket is located. |
Example
The example reads credentials from environment variables and accepts --region and --account-id as command-line flags. NewListVectorBucketsPaginator returns a paginator; the loop calls NextPage until HasNext returns false.
package main
import (
"context"
"flag"
"log"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/vectors"
)
var (
region string
accountId string
)
func init() {
flag.StringVar(®ion, "region", "", "The region in which the vector bucket is located.")
flag.StringVar(&accountId, "account-id", "", "The ID of the vector account.")
}
func main() {
flag.Parse()
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
if len(accountId) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, accountId required")
}
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region).WithAccountId(accountId)
client := vectors.NewVectorsClient(cfg)
request := &vectors.ListVectorBucketsRequest{}
p := client.NewListVectorBucketsPaginator(request)
var i int
log.Println("Vector Buckets:")
for p.HasNext() {
i++
page, err := p.NextPage(context.TODO())
if err != nil {
log.Fatalf("failed to get page %v, %v", i, err)
}
// Log the buckets found.
for _, b := range page.Buckets {
log.Printf("Bucket:%v, %v, %v\n", oss.ToString(b.Name), oss.ToString(b.ResourceGroupId), oss.ToString(b.Location))
}
}
}References
For the complete sample code, see list_vector_buckets.go.