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.

64 lines
1.3 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{BucketURL: u}
  13. c := cos.NewClient(b, &http.Client{
  14. Transport: &cos.AuthorizationTransport{
  15. SecretID: os.Getenv("COS_SECRETID"),
  16. SecretKey: os.Getenv("COS_SECRETKEY"),
  17. Transport: &debug.DebugRequestTransport{
  18. RequestHeader: true,
  19. RequestBody: true,
  20. ResponseHeader: true,
  21. ResponseBody: true,
  22. },
  23. },
  24. })
  25. opt := &cos.ObjectPutACLOptions{
  26. Header: &cos.ACLHeaderOptions{
  27. XCosACL: "private",
  28. },
  29. }
  30. name := "test/hello.txt"
  31. _, err := c.Object.PutACL(context.Background(), name, opt)
  32. if err != nil {
  33. panic(err)
  34. }
  35. // with body
  36. opt = &cos.ObjectPutACLOptions{
  37. Body: &cos.ACLXml{
  38. Owner: &cos.Owner{
  39. ID: "qcs::cam::uin/100000760461:uin/100000760461",
  40. },
  41. AccessControlList: []cos.ACLGrant{
  42. {
  43. Grantee: &cos.ACLGrantee{
  44. Type: "RootAccount",
  45. ID: "qcs::cam::uin/100000760461:uin/100000760461",
  46. },
  47. Permission: "FULL_CONTROL",
  48. },
  49. },
  50. },
  51. }
  52. _, err = c.Object.PutACL(context.Background(), name, opt)
  53. if err != nil {
  54. panic(err)
  55. }
  56. }