桶(Bucket)是存储对象(Object)的容器。对象都隶属于桶。
以下代码用于创建桶:
package sample
import ( "fmt" "github.com/journeymidnight/Yig-S3-SDK-Go/s3lib" ) func MakeBucketSample() { DeleteTestBucketAndObject() defer DeleteTestBucketAndObject() sc := s3lib.NewS3(endpoint, accessKey, secretKey) // Create a bucket err := sc.MakeBucket(bucketName) if err != nil { HandleError(err) } // Delete a bucket err = sc.DeleteBucket(bucketName) if err != nil { HandleError(err) } } |
以下代码用于在创建桶时指定桶的权限:
//Make bucket with ACL
err = sc.MakeBucketWithAcl(bucketName, "public-read") if err != nil { HandleError(err) } out, err := sc.GetBucketAcl(bucketName) if err != nil { HandleError(err) } fmt.Println("Get Bucket ACL:", out) err = sc.DeleteBucket(bucketName) if err != nil { HandleError(err) } |