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
3.4 KiB

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