bucket_acl.go 887 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package sample
  2. import (
  3. "fmt"
  4. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  5. )
  6. // BucketACLSample 展示了如何读取/设置存储空间的权限(Bucket ACL)
  7. func BucketACLSample() {
  8. // New Client
  9. client, err := oss.New(endpoint, accessID, accessKey)
  10. if err != nil {
  11. HandleError(err)
  12. }
  13. // 使用默认参数创建bucket
  14. err = client.CreateBucket(bucketName)
  15. if err != nil {
  16. HandleError(err)
  17. }
  18. // 场景:设置Bucket ACL,可选权限有ACLPrivate、ACLPublicRead、ACLPublicReadWrite
  19. err = client.SetBucketACL(bucketName, oss.ACLPublicRead)
  20. if err != nil {
  21. HandleError(err)
  22. }
  23. // 查看Bucket ACL
  24. gbar, err := client.GetBucketACL(bucketName)
  25. if err != nil {
  26. HandleError(err)
  27. }
  28. fmt.Println("Bucket ACL:", gbar.ACL)
  29. // 删除bucket
  30. err = client.DeleteBucket(bucketName)
  31. if err != nil {
  32. HandleError(err)
  33. }
  34. fmt.Println("BucketACLSample completed")
  35. }