查看生命周期规则
更新时间: 2019-03-14 10:05
您可以通过ObsClient.GetBucketLifecycleConfiguration查看桶的生命周期规则。以下代码展示了如何查看桶的生命周期规则:
- // 引入依赖包
- import (
- "fmt"
- "obs"
- )
- var ak = "*** Provide your Access Key ***"
- var sk = "*** Provide your Secret Key ***"
- var endpoint = "https://your-endpoint"
- // 创建ObsClient结构体
- var obsClient, _ = obs.New(ak, sk, endpoint)
- func main() {
- output, err := obsClient.GetBucketLifecycleConfiguration("bucketname")
- if err == nil {
- for index, lifecycleRule := range output.LifecycleRules {
- fmt.Printf("LifecycleRule[%d]:\n", index)
- fmt.Printf("ID:%s, Prefix:%s, Status:%s\n", lifecycleRule.ID, lifecycleRule.Prefix, lifecycleRule.Status)
- var date = ""
- for _, transition := range lifecycleRule.Transitions {
- if !transition.Date.IsZero() {
- date = transition.Date.String()
- }
- fmt.Printf("transition.StorageClass:%s, Transition.Date:%s, Transition.Days:%d\n", transition.StorageClass, date, transition.Days)
- }
- date = ""
- if !lifecycleRule.Expiration.Date.IsZero() {
- date = lifecycleRule.Expiration.Date.String()
- }
- fmt.Printf("Expiration.Date:%s, Expiration.Days:%d\n", lifecycleRule.Expiration.Date, lifecycleRule.Expiration.Days)
- for _, noncurrentVersionTransition := range lifecycleRule.NoncurrentVersionTransitions {
- fmt.Printf("noncurrentVersionTransition.StorageClass:%s, noncurrentVersionTransition.NoncurrentDays:%d\n",
- noncurrentVersionTransition.StorageClass, noncurrentVersionTransition.NoncurrentDays)
- }
- fmt.Printf("NoncurrentVersionExpiration.NoncurrentDays:%d\n", lifecycleRule.NoncurrentVersionExpiration.NoncurrentDays)
- }
- } else if obsError, ok := err.(obs.ObsError); ok {
- fmt.Printf("Code:%s\n", obsError.Code)
- fmt.Printf("Message:%s\n", obsError.Message)
- }
- }
父主题:生命周期管理