Manage bucket tagging using OSS SDK for Go 2.0
This topic describes how to manage the tags of a bucket.
Usage notes
-
The sample code in this topic uses the region ID
cn-hangzhouof the China (Hangzhou) region. By default, the public endpoint is used to access resources in a bucket. If you want to access resources in the bucket by using other Alibaba Cloud services in the same region in which the bucket is located, use the internal endpoint. For more information about Object Storage Service (OSS) regions and endpoints, see Regions and endpoints. -
In this topic, access credentials are obtained from environment variables. For more information about how to configure the access credentials, see Configure access credentials.
Method
Configure tags for a bucket
func (c *Client) PutBucketTags(ctx context.Context, request *PutBucketTagsRequest, optFns ...func(*Options)) (*PutBucketTagsResult, error)
Query the tags of a bucket
func (c *Client) GetBucketTags(ctx context.Context, request *GetBucketTagsRequest, optFns ...func(*Options)) (*GetBucketTagsResult, error)
Delete the tags of a bucket
func (c *Client) DeleteBucketTags(ctx context.Context, request *DeleteBucketTagsRequest, optFns ...func(*Options)) (*DeleteBucketTagsResult, error)
Request parameters
|
Parameter |
Type |
Description |
|
ctx |
context.Context |
The context of the request, which can be used to specify the total duration of the request. |
|
request |
*PutBucketTagsRequest |
Specifies the parameters of a specific API operation. For more information, see PutBucketTagsRequest. |
|
*GetBucketTagsRequest |
Specifies the parameters of a specific API operation. For more information, see GetBucketTagsRequest. |
|
|
*DeleteBucketTagsRequest |
Specifies the parameters of a specific API operation. For more information, see DeleteBucketTagsRequest. |
|
|
optFns |
...func(*Options) |
Optional. The operation-level parameter. For more information, see Options. |
Response parameters
|
Parameter |
Type |
Description |
|
result |
*PutBucketTagsResult |
The response to the operation. This parameter is valid when the value of err is nil. For more information, see PutBucketTagsResult. |
|
*GetBucketTagsRequest |
The response to the operation. This parameter is valid when the value of err is nil. For more information, see GetBucketTagsResult. |
|
|
*DeleteBucketTagsRequest |
The response to the operation. This parameter is valid when the value of err is nil. For more information, see DeleteBucketTagsResult. |
|
|
err |
error |
The status of the request. If the request fails, the value of err cannot be nil. |
Examples
References
-
For more information about the API operation that you can call to configure tags for a bucket, visit PutBucketTags.
-
For more information about the API operation that you can call to query the tags of a bucket, visit GetBucketTags.
-
For more information about the API operation that you can call to delete the tags of a bucket, visit DeleteBucketTags.