设置桶的生命周期配置
更新时间: 2019-03-13 10:23
功能说明
配置桶的生命周期规则,实现定时转换桶中对象的存储类型,以及定时删除桶中对象的功能。
方法定义
- func (obsClient ObsClient) SetBucketLifecycleConfiguration(input *SetBucketLifecycleConfigurationInput) (output *BaseModel, err error)
使用带授权信息URL的方法定义
- func (obsClient ObsClient) SetBucketLifecycleConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header, data io.Reader) (output *BaseModel, err error)
请求参数
参数名 | 类型 | 约束 |
---|---|---|
input | *SetBucketLifecycleConfigurationInput | 必选 |
返回结果
参数名 | 类型 |
---|---|
output | *BaseModel |
err | error |
代码样例
- func main() {
- input := &obs.SetBucketLifecycleConfigurationInput{}
- input.Bucket = "bucketname"
- var lifecycleRules [2]obs.LifecycleRule
- lifecycleRule0 := obs.LifecycleRule{}
- lifecycleRule0.ID = "rule0"
- lifecycleRule0.Prefix = "prefix0"
- lifecycleRule0.Status = obs.RuleStatusEnabled
- var transitions [2]obs.Transition
- transitions[0] = obs.Transition{}
- transitions[0].Days = 30
- transitions[0].StorageClass = obs.StorageClassWarm
- transitions[1] = obs.Transition{}
- transitions[1].Days = 60
- transitions[1].StorageClass = obs.StorageClassCold
- lifecycleRule0.Transitions = transitions[:]
- lifecycleRule0.Expiration.Days = 100
- lifecycleRule0.NoncurrentVersionExpiration.NoncurrentDays = 20
- lifecycleRules[0] = lifecycleRule0
- lifecycleRule1 := obs.LifecycleRule{}
- lifecycleRule1.Status = obs.RuleStatusEnabled
- lifecycleRule1.ID = "rule1"
- lifecycleRule1.Prefix = "prefix1"
- lifecycleRule1.Expiration.Date = time.Now().Add(time.Duration(24) * time.Hour)
- var noncurrentTransitions [2]obs.NoncurrentVersionTransition
- noncurrentTransitions[0] = obs.NoncurrentVersionTransition{}
- noncurrentTransitions[0].NoncurrentDays = 30
- noncurrentTransitions[0].StorageClass = obs.StorageClassWarm
- noncurrentTransitions[1] = obs.NoncurrentVersionTransition{}
- noncurrentTransitions[1].NoncurrentDays = 60
- noncurrentTransitions[1].StorageClass = obs.StorageClassCold
- lifecycleRule1.NoncurrentVersionTransitions = noncurrentTransitions[:]
- lifecycleRules[1] = lifecycleRule1
- input.LifecycleRules = lifecycleRules[:]
- output, err := obsClient.SetBucketLifecycleConfiguration(input)
- if err == nil {
- fmt.Printf("RequestId:%s\n", output.RequestId)
- } else {
- if obsError, ok := err.(obs.ObsError); ok {
- fmt.Println(obsError.Code)
- fmt.Println(obsError.Message)
- } else {
- fmt.Println(err)
- }
- }
- }
父主题:桶相关接口