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.

58 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://testhuanan-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. 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. Days: 10,
  35. StorageClass: "Standard",
  36. },
  37. },
  38. {
  39. ID: "123422",
  40. // If used for all objecs set Prefix:""
  41. Filter: &cos.BucketLifecycleFilter{Prefix: "gg"},
  42. Status: "Disabled",
  43. Expiration: &cos.BucketLifecycleExpiration{
  44. Days: 10,
  45. },
  46. },
  47. },
  48. }
  49. _, err := c.Bucket.PutLifecycle(context.Background(), lc)
  50. if err != nil {
  51. panic(err)
  52. }
  53. }