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.

107 lines
4.2 KiB

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