Manage versioning using OSS SDK for Go 2.0
Versioning applies to all objects in a bucket. After you enable versioning, you can recover any previous version of an object that was accidentally overwritten or deleted.
Notes
-
The sample code uses the region ID
cn-hangzhouof the China (Hangzhou) region and the public endpoint by default. To access resources in a bucket from other Alibaba Cloud services in the same region, use an internal endpoint. For more information about supported regions and endpoints, see OSS Regions and Endpoints. -
The sample code obtains access credentials from environment variables. For more information about how to configure access credentials, see Configure Access Credentials.
-
The
oss:PutBucketVersioningpermission is required to configure versioning for a bucket. Theoss:GetBucketVersioningpermission is required to query the versioning state of a bucket. For more information, see Grant Custom Permissions to RAM Users.
Methods
Configure the versioning state of a bucket
func (c *Client) PutBucketVersioning(ctx context.Context, request *PutBucketVersioningRequest, optFns ...func(*Options)) (*PutBucketVersioningResult, error)
Query the versioning state of a bucket
func (c *Client) GetBucketVersioning(ctx context.Context, request *GetBucketVersioningRequest, optFns ...func(*Options)) (*GetBucketVersioningResult, error)
Request parameters
|
Parameters |
Types |
Description |
|
ctx |
context.Context |
The request context. You can use this parameter to specify the total request duration. |
|
request |
*PutBucketVersioningRequest |
The request parameters for configuring bucket versioning. For more information, see PutBucketVersioningRequest. |
|
*GetBucketVersioningRequest |
The request parameters for querying the versioning state of a bucket. For more information, see GetBucketVersioningRequest. |
|
|
optFns |
...func(*Options) |
Optional. The operation-level parameters. For more information, see Options. |
Response parameters
|
Response parameters |
Types |
Description |
|
result |
*PutBucketVersioningResult |
The response. Available when err is nil. For more information, see PutBucketVersioningResult. |
|
*GetBucketVersioningResult |
The response. Available when err is nil. For more information, see GetBucketVersioningResult. |
|
|
err |
error |
The error information. A non-nil value indicates a failed request. |
Sample code
References
-
For the API operation used to configure bucket versioning, see PutBucketVersioning.
-
For the API operation used to query the versioning state of a bucket, see GetBucketVersioning.