Configure resource groups using OSS SDK for Go 2.0
This topic describes how to configure a resource group for an Object Storage Service (OSS) bucket and query the ID of a resource group to which the bucket belongs.
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 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.
To configure a resource group for a bucket, you must have the
oss:PutBucketResourceGrouppermission. To query the ID of the resource group to which a bucket belongs, you must have theoss:GetBucketResourceGrouppermission. For more information, see Grant a custom policy.
Method
Configure a resource group for a bucket
func (c *Client) PutBucketResourceGroup(ctx context.Context, request *PutBucketResourceGroupRequest, optFns ...func(*Options)) (*PutBucketResourceGroupResult, error)Query the ID of the resource group to which a bucket belongs
func (c *Client) GetBucketResourceGroup(ctx context.Context, request *GetBucketResourceGroupRequest, optFns ...func(*Options)) (*GetBucketResourceGroupResult, 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 | *PutBucketResourceGroupRequest | The parameters of a specific API operation. For more information, visit PutBucketResourceGroupRequest. |
*GetBucketResourceGroupRequest | The parameters of a specific API operation. For more information, visit GetBucketResourceGroupRequest. | |
optFns | ...func(*Options) | Optional. The operation-level parameter. For more information, visit Options. |
Response parameters
Parameter | Type | Description |
result | *PutBucketResourceGroupResult | The response to the operation. This parameter is valid when the value of err is nil. For more information, visit PutBucketResourceGroupResult. |
*GetBucketResourceGroupRequest | The response to the operation. This parameter is valid when the value of err is nil. For more information, visit GetBucketResourceGroupResult. | |
err | error | The status of the request. If the request fails, the value of err cannot be nil. |
Examples
References
For the complete sample code that is used to configure a resource group for a bucket, visit GitHub.
For more information about the API operation that you can call to configure a resource group for a bucket, visit PutBucketResourceGroup.
For the complete sample code that is used to query the ID of the resource group to which a bucket belongs, visit GitHub.
For more information about the API operation that you can call to query the ID of the resource group to which a bucket belongs, visit GetBucketResourceGroup.