The bucket name has to be globally unique. Make sure, your bucket name is different from the other users’.

Delete a bucket

You can use the Client.DeleteBucket operation to delete a bucket and specify the bucket name:

import"github.com/aliyun/aliyun-oss-go-sdk/oss"

client, err := oss.New("Endpoint","AccessKeyId","AccessKeySecret")

if err !=nil{

// HandleError(err)

}

err = client.DeleteBucket("my-bucket")

if err !=nil{

// HandleError(err)

}

Note:

You cannot delete a bucket if it has objects in it. Delete all the objects in the bucket before deleting it.

If the bucket to be deleted has unfinished upload requests, you must cancel the requests first using the Bucket.ListMultipartUploads and Bucket.AbortMultipartUpload operations. For usage, see OSS API documentation overview.

Check whether a bucket exists

Use the Client.IsBucketExist operation to check whether a bucket of the current user exists:

import"github.com/aliyun/aliyun-oss-go-sdk/oss"

client, err := oss.New("Endpoint","AccessKeyId","AccessKeySecret")

if err !=nil{

// HandleError(err)

}

isExist, err := client.IsBucketExist("my-bucket")

if err !=nil{

// HandleError(err)

}

Bucket access permissions

You can set the ACL policy of a bucket to allow or prohibit anonymous reads/writes to the bucket. For more information on ACL, see Access control.

Note: For example code of bucket ACL, see sample/bucket_acl.go.

View the ACL of a bucket

You can use Client.GetBucketACL to view the ACL policy of a bucket:

import"fmt"

import"github.com/aliyun/aliyun-oss-go-sdk/oss"

client, err := oss.New("Endpoint","AccessKeyId","AccessKeySecret")

if err !=nil{

// HandleError(err)

}

aclRes, err := client.GetBucketACL("my-bucket")

if err !=nil{

// HandleError(err)

}

fmt.Println("Bucket ACL:", aclRes.ACL)

Set the ACL policy of a bucket

You can use Client.SetBucketACL to configure the ACL policy of a bucket:

import"github.com/aliyun/aliyun-oss-go-sdk/oss"

client, err := oss.New("Endpoint","AccessKeyId","AccessKeySecret")

if err !=nil{

// HandleError(err)

}

err = client.SetBucketACL("my-bucket", oss.ACLPublicRead)

if err !=nil{

// HandleError(err)

}

Note: A bucket has three types of ACLs: private, public-read, and public-read-write. The three ACLs correspond to three constants (ACLPrivate, ACLPublicRead, and ACLPublicReadWrite) of Go SDK respectively.