最近更新时间:2024-11-11 19:47:33
以下代码用于设置存储空间清单规则:
package main
import (
"fmt"
"github.com/ks3sdklib/aws-sdk-go/aws"
"github.com/ks3sdklib/aws-sdk-go/aws/awsutil"
"github.com/ks3sdklib/aws-sdk-go/aws/credentials"
"github.com/ks3sdklib/aws-sdk-go/service/s3"
)
func main() {
// 创建访问凭证,请将<AccessKeyID>与<SecretAccessKey>替换成真正的值
cre := credentials.NewStaticCredentials("<AccessKeyID>", "<SecretAccessKey>", "")
// 创建S3Client,更多配置项请查看Go-SDK初始化文档
client := s3.New(&aws.Config{
Credentials: cre, // 访问凭证
Region: "BEIJING", // 填写您的Region
Endpoint: "ks3-cn-beijing.ksyuncs.com", // 填写您的Endpoint
})
// 填写存储空间名称
bucket := "<bucket_name>"
// 填写清单规则ID
id := "inventory-rule1"
// 构造存储空间清单规则
inventoryConfiguration := &s3.InventoryConfiguration{
Id: aws.String(id),
IsEnabled: aws.Boolean(true),
Filter: &s3.InventoryFilter{
Prefix: aws.String("abc/"),
},
Destination: &s3.Destination{
KS3BucketDestination: &s3.KS3BucketDestination{
Format: aws.String("CSV"),
Bucket: aws.String(bucket),
Prefix: aws.String("prefix/"),
},
},
Schedule: &s3.Schedule{
Frequency: aws.String("Once"),
},
OptionalFields: &s3.OptionalFields{
Field: []*string{
aws.String("Size"),
aws.String("LastModifiedDate"),
aws.String("ETag"),
aws.String("StorageClass"),
aws.String("IsMultipartUploaded"),
aws.String("EncryptionStatus"),
},
},
}
// 设置存储空间清单规则
resp, err := client.PutBucketInventory(&s3.PutBucketInventoryInput{
Bucket: aws.String(bucket), // 存储空间名称,必填
Id: aws.String(id), // 存储清单id,必填
InventoryConfiguration: inventoryConfiguration, // 存储清单规则,必填
})
if err != nil {
panic(err)
}
fmt.Println("结果:\n", awsutil.StringValue(resp))
}
有关设置存储空间清单规则详情,请参见 PUT Bucket Inventory。
以下代码用于获取存储空间清单规则:
package main
import (
"fmt"
"github.com/ks3sdklib/aws-sdk-go/aws"
"github.com/ks3sdklib/aws-sdk-go/aws/awsutil"
"github.com/ks3sdklib/aws-sdk-go/aws/credentials"
"github.com/ks3sdklib/aws-sdk-go/service/s3"
)
func main() {
// 创建访问凭证,请将<AccessKeyID>与<SecretAccessKey>替换成真正的值
cre := credentials.NewStaticCredentials("<AccessKeyID>", "<SecretAccessKey>", "")
// 创建S3Client,更多配置项请查看Go-SDK初始化文档
client := s3.New(&aws.Config{
Credentials: cre, // 访问凭证
Region: "BEIJING", // 填写您的Region
Endpoint: "ks3-cn-beijing.ksyuncs.com", // 填写您的Endpoint
})
// 填写存储空间名称
bucket := "<bucket_name>"
// 获取存储空间清单规则
resp, err := client.GetBucketInventory(&s3.GetBucketInventoryInput{
Bucket: aws.String(bucket), // 存储空间名称,必填
Id: aws.String("inventory-rule1"), // 存储清单id,必填
})
if err != nil {
panic(err)
}
fmt.Println("结果:\n", awsutil.StringValue(resp))
}
有关获取存储空间清单规则详情,请参见 GET Bucket Inventory。
以下代码用于删除存储空间清单规则:
package main
import (
"fmt"
"github.com/ks3sdklib/aws-sdk-go/aws"
"github.com/ks3sdklib/aws-sdk-go/aws/awsutil"
"github.com/ks3sdklib/aws-sdk-go/aws/credentials"
"github.com/ks3sdklib/aws-sdk-go/service/s3"
)
func main() {
// 创建访问凭证,请将<AccessKeyID>与<SecretAccessKey>替换成真正的值
cre := credentials.NewStaticCredentials("<AccessKeyID>", "<SecretAccessKey>", "")
// 创建S3Client,更多配置项请查看Go-SDK初始化文档
client := s3.New(&aws.Config{
Credentials: cre, // 访问凭证
Region: "BEIJING", // 填写您的Region
Endpoint: "ks3-cn-beijing.ksyuncs.com", // 填写您的Endpoint
})
// 填写存储空间名称
bucket := "<bucket_name>"
// 删除存储空间清单规则
resp, err := client.DeleteBucketInventory(&s3.DeleteBucketInventoryInput{
Bucket: aws.String(bucket), // 存储空间名称,必填
Id: aws.String("inventory-rule1"), // 存储清单id,必填
})
if err != nil {
panic(err)
}
fmt.Println("结果:\n", awsutil.StringValue(resp))
}
有关删除存储空间清单规则详情,请参见 DELETE Bucket Inventory。
纯净模式
鼠标选中内容,快速反馈问题