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.

92 lines
3.4 KiB

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