Call GetVectorBucket to retrieve information about a vector bucket.
Prerequisites
Before you begin, ensure that you have:
The OSS Go SDK V2 installed
The
oss:GetVectorBucketpermission granted via a RAM Policy or a bucket policyAccessKey credentials available as environment variables
By default, an Alibaba Cloud account has full permissions. A Resource Access Management (RAM) user or RAM role has no permissions by default and must be explicitly granted oss:GetVectorBucket.Permissions
| API | Action | Description |
|---|---|---|
| GetVectorBucket | oss:GetVectorBucket | Gets information about a vector bucket. |
Method definition
func (c *VectorsClient) GetVectorBucket(ctx context.Context, request *GetVectorBucketRequest, optFns ...func(*Options)) (*GetVectorBucketResult, error)Request parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | Yes | The request context. |
request | *GetVectorBucketRequest | Yes | The request parameters. The Bucket field (type *string) specifies the vector bucket name and is required. For all fields, see GetVectorBucketRequest. |
optFns | ...func(*Options) | No | Operation-level configuration overrides. See Options. |
Return values
| Value | Type | Description |
|---|---|---|
result | *GetVectorBucketResult | The vector bucket information. Valid only when err is nil. See GetVectorBucketResult. |
err | error | The error returned if the operation fails. nil on success. |
Sample code
The example below loads credentials from environment variables, builds a VectorsClient, and calls GetVectorBucket with the bucket name, region, and account ID passed as command-line flags.
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
bucketName string
accountId string
)
func init() {
flag.StringVar(®ion, "region", "", "The region in which the vector bucket is located.")
flag.StringVar(&bucketName, "bucket", "", "The name of the vector bucket.")
flag.StringVar(&accountId, "account-id", "", "The ID of the vector account.")
}
func main() {
flag.Parse()
if len(bucketName) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, bucket name required")
}
if len(region) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, region required")
}
if len(accountId) == 0 {
flag.PrintDefaults()
log.Fatalf("invalid parameters, accounId required")
}
cfg := oss.LoadDefaultConfig().
WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()).
WithRegion(region).WithAccountId(accountId)
client := vectors.NewVectorsClient(cfg)
request := &vectors.GetVectorBucketRequest{
Bucket: oss.Ptr(bucketName),
}
result, err := client.GetVectorBucket(context.TODO(), request)
if err != nil {
log.Fatalf("failed to get vector bucket %v", err)
}
log.Printf("get vector bucket result:%#v\n", result)
}Run the example with:
go run main.go --region <region-id> --bucket <bucket-name> --account-id <account-id>Replace the placeholders with your actual values:
| Placeholder | Description | Example |
|---|---|---|
<region-id> | The region where the vector bucket is located. | cn-hangzhou |
<bucket-name> | The name of the vector bucket. | my-vector-bucket |
<account-id> | The ID of the vector account. | 1234567890 |
References
Complete sample code: get_vector_bucket.go
REST API reference: GetVectorBucket