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.

47 lines
1.0 KiB

  1. package main
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "os"
  7. "net/http"
  8. "github.com/tencentyun/cos-go-sdk-v5"
  9. "github.com/tencentyun/cos-go-sdk-v5/debug"
  10. )
  11. func main() {
  12. u, _ := url.Parse("https://test-1259654469.cos.ap-guangzhou.myqcloud.com")
  13. b := &cos.BaseURL{
  14. BucketURL: u,
  15. }
  16. c := cos.NewClient(b, &http.Client{
  17. Transport: &cos.AuthorizationTransport{
  18. SecretID: os.Getenv("COS_SECRETID"),
  19. SecretKey: os.Getenv("COS_SECRETKEY"),
  20. Transport: &debug.DebugRequestTransport{
  21. RequestHeader: true,
  22. RequestBody: true,
  23. ResponseHeader: true,
  24. ResponseBody: true,
  25. },
  26. },
  27. })
  28. v, _, err := c.Bucket.GetLifecycle(context.Background())
  29. if err != nil {
  30. panic(err)
  31. }
  32. for _, r := range v.Rules {
  33. fmt.Printf("%+v\n", r.ID)
  34. fmt.Printf("%+v\n", r.Filter)
  35. fmt.Printf("%+v\n", r.Status)
  36. fmt.Printf("%+v\n", r.Transition)
  37. fmt.Printf("%+v\n", r.Expiration)
  38. fmt.Printf("%+v\n", r.NoncurrentVersionExpiration)
  39. fmt.Printf("%+v\n", r.NoncurrentVersionTransition)
  40. fmt.Printf("%+v\n", r.AbortIncompleteMultipartUpload)
  41. }
  42. }