Versioning

Last updated: 2021-01-12 18:32:04

    Overview

    This document provides an overview of APIs and SDK code samples related to versioning.

    API Operation Description
    PUT Bucket versioning Setting versioning Sets versioning for a bucket
    GET Bucket versioning Querying versioning Queries the versioning configuration of a bucket

    Setting Versioning

    Feature description

    This API (PUT Bucket versioning) is used to set the versioning configuration for a bucket.

    Method prototype

    func (s *BucketService) PutVersioning(ctx context.Context, opt *BucketPutVersionOptions) (*Response, error)

    Sample request

    opt := &cos.BucketPutVersionOptions{
        // Enabled or Suspended; once enabled, versioning can only be paused but not deleted.
        Status: "Enabled",
    }
    _, err := client.Bucket.PutVersioning(context.Background(), opt)
    if err != nil {
        panic(err)
    }

    Parameter description

    type BucketPutVersionOptions struct {
        Status  string
    }
    Parameter Name Description Type
    BucketPutVersionOptions Versioning policies struct
    Status Indicates whether versioning is enabled. Enumerated values: Suspended (versioning is paused), Enabled (versioning is enabled) string

    Querying Versioning

    Feature description

    This API (GET Bucket versioning) is used to query the versioning configuration of a bucket.

    Method prototype

    func (s *BucketService) GetVersioning(ctx context.Context) (*BucketGetVersionResult, *Response, error)

    Sample request

    _, _, err := client.Bucket.GetVersioning(context.Background())
    if err != nil {
        panic(err)
    }

    Response description

    type BucketGetVersionResult struct {
        Status  string
    }
    Parameter Name Description Type
    BucketGetVersionResult Versioning policies struct
    Status Indicates whether versioning is enabled. Enumerated values: Suspended (versioning is paused), Enabled (versioning is enabled) string