"github.com/volcengine/ve-tos-golang-sdk/v2/tos"
func checkErr(err error) {
if serverErr, ok := err.(*tos.TosServerError); ok {
fmt.Println("Error:", serverErr.Error())
fmt.Println("Request ID:", serverErr.RequestID)
fmt.Println("Response Status Code:", serverErr.StatusCode)
fmt.Println("Response Header:", serverErr.Header)
fmt.Println("Response Err Code:", serverErr.Code)
fmt.Println("Response Err Msg:", serverErr.Message)
} else if clientErr, ok := err.(*tos.TosClientError); ok {
fmt.Println("Error:", clientErr.Error())
fmt.Println("Client Cause Err:", clientErr.Cause.Error())
fmt.Println("Error:", err)
accessKey = os.Getenv("TOS_ACCESS_KEY")
secretKey = os.Getenv("TOS_SECRET_KEY")
endpoint = "your endpoint"
bucketName = "*** Provide your bucket name ***"
ctx = context.Background()
client, err := tos.NewClientV2(endpoint, tos.WithRegion(region), tos.WithCredentials(tos.NewStaticCredentials(accessKey, secretKey)))
getOutput, err := client.GetBucketLifecycle(ctx, &tos.GetBucketLifecycleInput{Bucket: bucketName})
fmt.Println("GetBucketLifecycle Request ID:", getOutput.RequestID)
fmt.Println("GetBucketLifecycle Rules Length:", len(getOutput.Rules))
for _, rule := range getOutput.Rules {
fmt.Println("Rule ID:", rule.ID)
fmt.Println("Rule Prefix:", rule.Prefix)
fmt.Println("Rule Status:", rule.Status)
fmt.Println("Rule Transitions:", rule.Transitions)
fmt.Println("Rule Expiration:", rule.Expiration)
fmt.Println("Rule NonCurrentVersionTransition:", rule.NonCurrentVersionTransition)
fmt.Println("Rule NoCurrentVersionExpiration:", rule.NoCurrentVersionExpiration)
for key, value := range rule.Tag {
fmt.Println("Rule Tag Key:", key)
fmt.Println("Rule Tag Value:", value)
fmt.Println("Rule AbortInCompleteMultipartUpload:", rule.AbortInCompleteMultipartUpload)