查看PDF

获取桶的生命周期配置

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

功能说明

获取桶的生命周期规则。

方法定义

  1. func (obsClient ObsClient) GetBucketLifecycleConfiguration(bucketName string) (output *GetBucketLifecycleConfigurationOutput, err error)

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

  1. func (obsClient ObsClient) GetBucketLifecycleConfigurationWithSignedUrl(signedUrl string, actualSignedRequestHeaders http.Header) (output *GetBucketLifecycleConfigurationOutput, err error)

请求参数


参数名

类型

约束

说明

bucketName

string

必选

桶名。

返回结果


参数名

类型

output

*GetBucketPolicyOutput

err

error

代码样例

  1. func main() {
  2. output, err := obsClient.GetBucketLifecycleConfiguration("bucketname")
  3. if err == nil {
  4. fmt.Printf("RequestId:%s\n", output.RequestId)
  5. for index, lifecycleRule := range output.LifecycleRules {
  6. fmt.Printf("LifecycleRule[%d]:\n", index)
  7. fmt.Printf("ID:%s, Prefix:%s, Status:%s\n", lifecycleRule.ID, lifecycleRule.Prefix, lifecycleRule.Status)
  8.  
  9. date := ""
  10. for _, transition := range lifecycleRule.Transitions {
  11. if !transition.Date.IsZero() {
  12. date = transition.Date.String()
  13. }
  14. fmt.Printf("transition.StorageClass:%s, Transition.Date:%s, Transition.Days:%d\n", transition.StorageClass, date, transition.Days)
  15. }
  16.  
  17. date = ""
  18. if !lifecycleRule.Expiration.Date.IsZero() {
  19. date = lifecycleRule.Expiration.Date.String()
  20. }
  21. fmt.Printf("Expiration.Date:%s, Expiration.Days:%d\n", lifecycleRule.Expiration.Date, lifecycleRule.Expiration.Days)
  22.  
  23. for _, noncurrentVersionTransition := range lifecycleRule.NoncurrentVersionTransitions {
  24. fmt.Printf("noncurrentVersionTransition.StorageClass:%s, noncurrentVersionTransition.NoncurrentDays:%d\n",
  25. noncurrentVersionTransition.StorageClass, noncurrentVersionTransition.NoncurrentDays)
  26. }
  27. fmt.Printf("NoncurrentVersionExpiration.NoncurrentDays:%d\n", lifecycleRule.NoncurrentVersionExpiration.NoncurrentDays)
  28. }
  29. } else {
  30. if obsError, ok := err.(obs.ObsError); ok {
  31. fmt.Println(obsError.Code)
  32. fmt.Println(obsError.Message)
  33. } else {
  34. fmt.Println(err)
  35. }
  36. }
  37. }

父主题:桶相关接口