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.

74 lines
1.6 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-1259654469.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. lc := &cos.BucketPutLifecycleOptions{
  28. Rules: []cos.BucketLifecycleRule{
  29. {
  30. ID: "1234",
  31. Filter: &cos.BucketLifecycleFilter{Prefix: "test"},
  32. Status: "Enabled",
  33. Transition: []cos.BucketLifecycleTransition{
  34. {
  35. Days: 30,
  36. StorageClass: "STANDARD_IA",
  37. },
  38. {
  39. Days: 90,
  40. StorageClass: "ARCHIVE",
  41. },
  42. },
  43. Expiration: &cos.BucketLifecycleExpiration{
  44. Days: 360,
  45. },
  46. NoncurrentVersionExpiration: &cos.BucketLifecycleNoncurrentVersion{
  47. NoncurrentDays: 360,
  48. },
  49. NoncurrentVersionTransition: []cos.BucketLifecycleNoncurrentVersion{
  50. {
  51. NoncurrentDays: 90,
  52. StorageClass: "ARCHIVE",
  53. },
  54. {
  55. NoncurrentDays: 180,
  56. StorageClass: "DEEP_ARCHIVE",
  57. },
  58. },
  59. AbortIncompleteMultipartUpload: &cos.BucketLifecycleAbortIncompleteMultipartUpload{
  60. DaysAfterInitiation: 90,
  61. },
  62. },
  63. },
  64. }
  65. _, err := c.Bucket.PutLifecycle(context.Background(), lc)
  66. if err != nil {
  67. panic(err)
  68. }
  69. }