查看生命周期规则

更新时间: 2019-03-14 10:05

您可以通过ObsClient.GetBucketLifecycleConfiguration查看桶的生命周期规则。以下代码展示了如何查看桶的生命周期规则:

  1. // 引入依赖包
  2. import (
  3. "fmt"
  4. "obs"
  5. )
  6.  
  7. var ak = "*** Provide your Access Key ***"
  8. var sk = "*** Provide your Secret Key ***"
  9. var endpoint = "https://your-endpoint"
  10.  
  11. // 创建ObsClient结构体
  12. var obsClient, _ = obs.New(ak, sk, endpoint)
  13.  
  14. func main() {
  15. output, err := obsClient.GetBucketLifecycleConfiguration("bucketname")
  16. if err == nil {
  17. for index, lifecycleRule := range output.LifecycleRules {
  18. fmt.Printf("LifecycleRule[%d]:\n", index)
  19. fmt.Printf("ID:%s, Prefix:%s, Status:%s\n", lifecycleRule.ID, lifecycleRule.Prefix, lifecycleRule.Status)
  20.  
  21. var date = ""
  22. for _, transition := range lifecycleRule.Transitions {
  23. if !transition.Date.IsZero() {
  24. date = transition.Date.String()
  25. }
  26. fmt.Printf("transition.StorageClass:%s, Transition.Date:%s, Transition.Days:%d\n", transition.StorageClass, date, transition.Days)
  27. }
  28. date = ""
  29.  
  30. if !lifecycleRule.Expiration.Date.IsZero() {
  31. date = lifecycleRule.Expiration.Date.String()
  32. }
  33. fmt.Printf("Expiration.Date:%s, Expiration.Days:%d\n", lifecycleRule.Expiration.Date, lifecycleRule.Expiration.Days)
  34.  
  35. for _, noncurrentVersionTransition := range lifecycleRule.NoncurrentVersionTransitions {
  36. fmt.Printf("noncurrentVersionTransition.StorageClass:%s, noncurrentVersionTransition.NoncurrentDays:%d\n",
  37. noncurrentVersionTransition.StorageClass, noncurrentVersionTransition.NoncurrentDays)
  38. }
  39. fmt.Printf("NoncurrentVersionExpiration.NoncurrentDays:%d\n", lifecycleRule.NoncurrentVersionExpiration.NoncurrentDays)
  40. }
  41. } else if obsError, ok := err.(obs.ObsError); ok {
  42. fmt.Printf("Code:%s\n", obsError.Code)
  43. fmt.Printf("Message:%s\n", obsError.Message)
  44. }
  45. }

父主题:生命周期管理