设置生命周期

功能说明

设置指定 Bucket 的生命周期配置。

方法原型

  1. func (s *BucketService) PutLifecycle(ctx context.Context, opt *BucketPutLifecycleOptions) (*Response, error)

请求示例

  1. lc := &cos.BucketPutLifecycleOptions{
  2. Rules: []cos.BucketLifecycleRule{
  3. {
  4. ID: "1234",
  5. Filter: &cos.BucketLifecycleFilter{Prefix: "test"},
  6. Status: "Enabled",
  7. Transition: &cos.BucketLifecycleTransition{
  8. Days: 10,
  9. StorageClass: "Standard",
  10. },
  11. },
  12. {
  13. ID: "123422",
  14. Filter: &cos.BucketLifecycleFilter{Prefix: "gg"},
  15. Status: "Disabled",
  16. Expiration: &cos.BucketLifecycleExpiration{
  17. Days: 10,
  18. },
  19. },
  20. },
  21. }
  22. resp, err := client.Bucket.PutLifecycle(context.Background(), lc)

参数说明

  1. type BucketLifecycleRule struct {
  2. ID string
  3. Status string
  4. Filter *BucketLifecycleFilter
  5. Transition *BucketLifecycleTransition
  6. Expiration *BucketLifecycleExpiration
  7. AbortIncompleteMultipartUpload *BucketLifecycleAbortIncompleteMultipartUpload
  8. }
  9. type BucketLifecycleFilter struct {
  10. Prefix string
  11. }
  12. type BucketLifecycleTransition struct {
  13. Date string
  14. Days int
  15. StorageClass string
  16. }
  17. type BucketLifecycleExpiration struct {
  18. Date string
  19. Days int
  20. }
  21. type BucketLifecycleAbortIncompleteMultipartUpload struct {
  22. DaysAfterInitiation string
  23. }
参数名称参数描述类型必填
BucketLifecycleRule设置对应的规则,包括 ID,Filter,Status,Expiration,Transition,AbortIncompleteMultipartUploadList
ID设置规则的 IDstring
Status设置 Rule 是否启用,可选值为 Enabled 或者 Disabledstring
Filter用于描述规则影响的 Object 集合,如需设置 bucket 中的所有 objects,请设置 Prefix 为空struct
Transition设置 Object 转换存储类型规则,可以指定天数 Days 或者指定日期 Date,Date 的格式必须是 GMT ISO 8601。StorageClass 可选 Standard_IA,Archive,可以同时设置多条此类规则struct
Expiration设置 Object 过期规则,可以指定天数 Days 或者指定日期 Date,Date 的格式必须是 GMT ISO 8601struct
AbortIncompleteMultipartUpload指明分块上传开始后多少天内必须完成上传struct