You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.2 KiB

  1. package main
  2. import (
  3. "context"
  4. "net/url"
  5. "os"
  6. "net/http"
  7. "github.com/tencentyun/cos-go-sdk-v5"
  8. "github.com/tencentyun/cos-go-sdk-v5/debug"
  9. )
  10. func main() {
  11. u, _ := url.Parse("https://test-1253846586.cos.ap-guangzhou.myqcloud.com")
  12. b := &cos.BaseURL{
  13. BucketURL: u,
  14. }
  15. c := cos.NewClient(b, &http.Client{
  16. Transport: &cos.AuthorizationTransport{
  17. SecretID: os.Getenv("COS_SECRETID"),
  18. SecretKey: os.Getenv("COS_SECRETKEY"),
  19. Transport: &debug.DebugRequestTransport{
  20. RequestHeader: true,
  21. RequestBody: true,
  22. ResponseHeader: true,
  23. ResponseBody: true,
  24. },
  25. },
  26. })
  27. // with header
  28. opt := &cos.BucketPutACLOptions{
  29. Header: &cos.ACLHeaderOptions{
  30. XCosACL: "private",
  31. },
  32. }
  33. _, err := c.Bucket.PutACL(context.Background(), opt)
  34. if err != nil {
  35. panic(err)
  36. }
  37. // with body
  38. opt = &cos.BucketPutACLOptions{
  39. Body: &cos.ACLXml{
  40. Owner: &cos.Owner{
  41. ID: "qcs::cam::uin/100000760461:uin/100000760461",
  42. },
  43. AccessControlList: []cos.ACLGrant{
  44. {
  45. Grantee: &cos.ACLGrantee{
  46. Type: "RootAccount",
  47. ID: "qcs::cam::uin/100000760461:uin/100000760461",
  48. },
  49. Permission: "FULL_CONTROL",
  50. },
  51. },
  52. },
  53. }
  54. _, err = c.Bucket.PutACL(context.Background(), opt)
  55. if err != nil {
  56. panic(err)
  57. }
  58. }