本文介绍如何管理生命周期。
生命周期规则介绍
UOS支持设置生命周期(Lifecycle)规则,自动删除过期的文件和碎片,或将到期的文件转储为低频或归档存储类型,从而节省存储费用。每条规则包含:
设置和获取生命周期规则
以下代码用于设置生命周期规则:
package sample
import ( "fmt" "github.com/journeymidnight/Yig-S3-SDK-Go/s3lib" "github.com/journeymidnight/aws-sdk-go/aws" "github.com/journeymidnight/aws-sdk-go/service/s3" ) func BucketLifecycleSample() { DeleteTestBucketAndObject() defer DeleteTestBucketAndObject() sc := s3lib.NewS3(endpoint, accessKey, secretKey) err := sc.MakeBucket(bucketName) if err != nil { HandleError(err) } //put bucket lifeCycle rules := &s3.LifecycleConfiguration{ Rules: []*s3.Rule{ { Expiration: &s3.LifecycleExpiration{ Days: aws.Int64(3650), }, Prefix: aws.String("documents/"), ID: aws.String("TestOnly"), Status: aws.String("Enabled"), Transition: &s3.Transition{ Days: aws.Int64(365), StorageClass: aws.String("GLACIER"), }, }, }, } err = sc.PutBucketLifeCycle(bucketName, rules) if err != nil { HandleError(err) } //get bucket lifeCycle out, err := sc.GetBucketLifeCycle(bucketName) if err != nil { HandleError(err) } fmt.Println("Get Bucket Life Cycle", out) //Delete bucket lifeCycle err = sc.DeleteBucketLifeCycle(bucketName) if err != nil { HandleError(err) } fmt.Printf("BucketLifecycleSample Run Success !\n\n") } |