bucket_acl.go 869 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package sample
  2. import (
  3. "fmt"
  4. "github.com/aliyun/aliyun-oss-go-sdk/oss"
  5. )
  6. // BucketACLSample shows how to get and set the 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. // Create a bucket with default parameters
  14. err = client.CreateBucket(bucketName)
  15. if err != nil {
  16. HandleError(err)
  17. }
  18. // Set bucket ACL. The valid ACLs are ACLPrivate、ACLPublicRead、ACLPublicReadWrite
  19. err = client.SetBucketACL(bucketName, oss.ACLPublicRead)
  20. if err != nil {
  21. HandleError(err)
  22. }
  23. // Get bucket ACL
  24. gbar, err := client.GetBucketACL(bucketName)
  25. if err != nil {
  26. HandleError(err)
  27. }
  28. fmt.Println("Bucket ACL:", gbar.ACL)
  29. // Delete the bucket
  30. err = client.DeleteBucket(bucketName)
  31. if err != nil {
  32. HandleError(err)
  33. }
  34. fmt.Println("BucketACLSample completed")
  35. }