简介
本文档提供关于对象存储(COS)向量存储桶服务中删除向量桶策略(DeleteVectorBucketPolicy)API 的 Go SDK 使用说明和示例代码。
功能说明
DeleteVectorBucketPolicy 接口用于删除指定向量存储桶的访问策略配置。注意:
调用该接口会删除对应向量桶配置的所有访问控制策略,请谨慎操作。
方法原型
func (s *VectorService) DeleteVectorBucketPolicy(ctx context.Context, opt *DeleteVectorBucketPolicyOptions) (*Response, error)
请求参数说明
DeleteVectorBucketPolicyOptions 结构体字段说明:参数 | 描述 | 类型 | 是否必填 |
VectorBucketName | 向量桶名称,格式为 <BucketName-APPID>,例如 examplebucket-1250000000。支持小写字母、数字和 -,长度限制为3-63个字符。 | string | 是 |
返回结果说明
调用成功后,将返回
(*Response, error) 两个值。本方法无特殊的业务返回字段,当 error == nil 时表示删除成功。返回值 | 描述 | 类型 |
resp | 响应头信息,包含 HTTP 响应的详细对象等。 | *cos.Response |
err | 错误信息。如果请求成功,返回 nil。 | error |
如果请求失败,将返回非
nil 的 error。向量检索相关的业务错误(如资源不存在等)会封装为 *cos.VectorErrorResponse 结构,您可以通过 cos.IsVectorError() 辅助函数判断并获取详细错误信息。详细的错误处理方式、VectorErrorResponse 结构体说明及服务端错误码列表请参见 异常处理 文档。使用案例
package mainimport ("context""fmt""net/http""os"cos "github.com/tencentyun/cos-go-sdk-v5")func main() {// 生成 Vector 基础 URL,第二个参数控制是否使用 HTTPS,建议为 truevectorURL, _ := cos.NewVectorURL("ap-guangzhou", true)// 初始化 Client,设置 VectorURL 及鉴权client := cos.NewClient(&cos.BaseURL{VectorURL: vectorURL}, &http.Client{Transport: &cos.AuthorizationTransport{SecretID: os.Getenv("COS_VECTORS_SECRET_ID"),SecretKey: os.Getenv("COS_VECTORS_SECRET_KEY"),},})// 向量桶名称格式必须为:BucketName-APPIDbucketName := "examplebucket-1250000000"opt := &cos.DeleteVectorBucketPolicyOptions{VectorBucketName: bucketName,}// 调用删除向量桶策略方法_, err := client.Vector.DeleteVectorBucketPolicy(context.Background(), opt)if err != nil {if vecErr, ok := cos.IsVectorError(err); ok {fmt.Printf("向量服务错误,错误码: %s, 错误信息: %s, 请求ID: %s\\n",vecErr.Code, vecErr.Message, vecErr.RequestID)} else {fmt.Printf("请求失败: %v\\n", err)}return}fmt.Printf("成功删除向量桶策略: %s\\n", bucketName)}