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.

99 lines
3.6 KiB

  1. package cos
  2. import (
  3. "context"
  4. "encoding/xml"
  5. "net/http"
  6. )
  7. type BucketLifecycleAndOperator struct {
  8. Prefix string `xml:"Prefix,omitempty"`
  9. Tag []BucketTaggingTag `xml:"Tag,omitempty"`
  10. }
  11. // BucketLifecycleFilter is the param of BucketLifecycleRule
  12. type BucketLifecycleFilter struct {
  13. Prefix string `xml:"Prefix,omitempty"`
  14. Tag *BucketTaggingTag `xml:"Tag,omitempty"`
  15. And *BucketLifecycleAndOperator `xml:"And,omitempty"`
  16. }
  17. // BucketLifecycleExpiration is the param of BucketLifecycleRule
  18. type BucketLifecycleExpiration struct {
  19. Date string `xml:"Date,omitempty"`
  20. Days int `xml:"Days,omitempty"`
  21. }
  22. // BucketLifecycleTransition is the param of BucketLifecycleRule
  23. type BucketLifecycleTransition struct {
  24. Date string `xml:"Date,omitempty"`
  25. Days int `xml:"Days,omitempty"`
  26. StorageClass string
  27. }
  28. // BucketLifecycleAbortIncompleteMultipartUpload is the param of BucketLifecycleRule
  29. type BucketLifecycleAbortIncompleteMultipartUpload struct {
  30. DaysAfterInitiation int `xml:"DaysAfterInitiation,omitempty"`
  31. }
  32. // BucketLifecycleRule is the rule of BucketLifecycle
  33. type BucketLifecycleRule struct {
  34. ID string `xml:"ID,omitempty"`
  35. Status string
  36. Filter *BucketLifecycleFilter `xml:"Filter,omitempty"`
  37. Transition *BucketLifecycleTransition `xml:"Transition,omitempty"`
  38. Expiration *BucketLifecycleExpiration `xml:"Expiration,omitempty"`
  39. AbortIncompleteMultipartUpload *BucketLifecycleAbortIncompleteMultipartUpload `xml:"AbortIncompleteMultipartUpload,omitempty"`
  40. }
  41. // BucketGetLifecycleResult is the result of BucketGetLifecycle
  42. type BucketGetLifecycleResult struct {
  43. XMLName xml.Name `xml:"LifecycleConfiguration"`
  44. Rules []BucketLifecycleRule `xml:"Rule,omitempty"`
  45. }
  46. // GetLifecycle 请求实现读取生命周期管理的配置。当配置不存在时,返回404 Not Found。
  47. // https://www.qcloud.com/document/product/436/8278
  48. func (s *BucketService) GetLifecycle(ctx context.Context) (*BucketGetLifecycleResult, *Response, error) {
  49. var res BucketGetLifecycleResult
  50. sendOpt := sendOptions{
  51. baseURL: s.client.BaseURL.BucketURL,
  52. uri: "/?lifecycle",
  53. method: http.MethodGet,
  54. result: &res,
  55. }
  56. resp, err := s.client.send(ctx, &sendOpt)
  57. return &res, resp, err
  58. }
  59. // BucketPutLifecycleOptions is the option of PutBucketLifecycle
  60. type BucketPutLifecycleOptions struct {
  61. XMLName xml.Name `xml:"LifecycleConfiguration"`
  62. Rules []BucketLifecycleRule `xml:"Rule,omitempty"`
  63. }
  64. // PutLifecycle 请求实现设置生命周期管理的功能。您可以通过该请求实现数据的生命周期管理配置和定期删除。
  65. // 此请求为覆盖操作,上传新的配置文件将覆盖之前的配置文件。生命周期管理对文件和文件夹同时生效。
  66. // https://www.qcloud.com/document/product/436/8280
  67. func (s *BucketService) PutLifecycle(ctx context.Context, opt *BucketPutLifecycleOptions) (*Response, error) {
  68. sendOpt := sendOptions{
  69. baseURL: s.client.BaseURL.BucketURL,
  70. uri: "/?lifecycle",
  71. method: http.MethodPut,
  72. body: opt,
  73. }
  74. resp, err := s.client.send(ctx, &sendOpt)
  75. return resp, err
  76. }
  77. // DeleteLifecycle 请求实现删除生命周期管理。
  78. // https://www.qcloud.com/document/product/436/8284
  79. func (s *BucketService) DeleteLifecycle(ctx context.Context) (*Response, error) {
  80. sendOpt := sendOptions{
  81. baseURL: s.client.BaseURL.BucketURL,
  82. uri: "/?lifecycle",
  83. method: http.MethodDelete,
  84. }
  85. resp, err := s.client.send(ctx, &sendOpt)
  86. return resp, err
  87. }