查看PDF

设置桶的生命周期配置

更新时间: 2019-03-13 10:23

功能说明

配置桶的生命周期规则,实现定时转换桶中对象的存储类型,以及定时删除桶中对象的功能。

方法定义

  1. func (obsClient ObsClient) SetBucketLifecycleConfiguration(input *SetBucketLifecycleConfigurationInput) (output *BaseModel, err error)

使用带授权信息URL的方法定义

  1. func (obsClient ObsClient) SetBucketLifecycleConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error)

请求参数


参数名

类型

约束

input

*SetBucketLifecycleConfigurationInput

必选

返回结果


参数名

类型

output

*BaseModel

err

error

代码样例

  1. func main() {
  2. input := &obs.SetBucketLifecycleConfigurationInput{}
  3. input.Bucket = "bucketname"
  4.  
  5. var lifecycleRules [2]obs.LifecycleRule
  6. lifecycleRule0 := obs.LifecycleRule{}
  7. lifecycleRule0.ID = "rule0"
  8. lifecycleRule0.Prefix = "prefix0"
  9. lifecycleRule0.Status = obs.RuleStatusEnabled
  10.  
  11. var transitions [2]obs.Transition
  12. transitions[0] = obs.Transition{}
  13. transitions[0].Days = 30
  14. transitions[0].StorageClass = obs.StorageClassWarm
  15.  
  16. transitions[1] = obs.Transition{}
  17. transitions[1].Days = 60
  18. transitions[1].StorageClass = obs.StorageClassCold
  19. lifecycleRule0.Transitions = transitions[:]
  20.  
  21. lifecycleRule0.Expiration.Days = 100
  22. lifecycleRule0.NoncurrentVersionExpiration.NoncurrentDays = 20
  23.  
  24. lifecycleRules[0] = lifecycleRule0
  25.  
  26. lifecycleRule1 := obs.LifecycleRule{}
  27. lifecycleRule1.Status = obs.RuleStatusEnabled
  28. lifecycleRule1.ID = "rule1"
  29. lifecycleRule1.Prefix = "prefix1"
  30. lifecycleRule1.Expiration.Date = time.Now().Add(time.Duration(24) * time.Hour)
  31.  
  32. var noncurrentTransitions [2]obs.NoncurrentVersionTransition
  33. noncurrentTransitions[0] = obs.NoncurrentVersionTransition{}
  34. noncurrentTransitions[0].NoncurrentDays = 30
  35. noncurrentTransitions[0].StorageClass = obs.StorageClassWarm
  36.  
  37. noncurrentTransitions[1] = obs.NoncurrentVersionTransition{}
  38. noncurrentTransitions[1].NoncurrentDays = 60
  39. noncurrentTransitions[1].StorageClass = obs.StorageClassCold
  40. lifecycleRule1.NoncurrentVersionTransitions = noncurrentTransitions[:]
  41. lifecycleRules[1] = lifecycleRule1
  42.  
  43. input.LifecycleRules = lifecycleRules[:]
  44.  
  45. output, err := obsClient.SetBucketLifecycleConfiguration(input)
  46. if err == nil {
  47. fmt.Printf("RequestId:%s\n", output.RequestId)
  48. } else {
  49. if obsError, ok := err.(obs.ObsError); ok {
  50. fmt.Println(obsError.Code)
  51. fmt.Println(obsError.Message)
  52. } else {
  53. fmt.Println(err)
  54. }
  55. }
  56. }

父主题:桶相关接口