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.

51 lines
1.1 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://alanbj-1251668577.cos.ap-beijing.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. opt := &cos.PutBucketReplicationOptions{
  28. // qcs::cam::uin/[UIN]:uin/[Subaccount]
  29. Role: "qcs::cam::uin/2779643970:uin/2779643970",
  30. Rule: []cos.BucketReplicationRule{
  31. {
  32. ID: "1",
  33. // Enabled or Disabled
  34. Status: "Enabled",
  35. Destination: &cos.ReplicationDestination{
  36. // qcs::cos:[Region]::[Bucketname-Appid]
  37. Bucket: "qcs::cos:ap-guangzhou::alangz-1251668577",
  38. },
  39. },
  40. },
  41. }
  42. _, err := c.Bucket.PutBucketReplication(context.Background(), opt)
  43. if err != nil {
  44. panic(err)
  45. }
  46. }