【发布时间】:2019-03-17 16:28:19
【问题描述】:
我想删除bucket/userID。
但是bucket/userID下有很多文件
我必须实现删除bucket/userID,需要使用ListObjects 然后DeleteObjects。
函数ListObjects 返回result.Contents 是[]*s3.Object
但是DeleteObjects 需要[]*s3.ObjectIdentifier。
我无法将[]*s3.Object 转换为[]*s3.ObjectIdentifier。
在这段代码中,发生了错误invalid memory address or nil pointer dereference
type Object struct {
_ struct{} `type:"structure"`
ETag *string `type:"string"`
Key *string `min:"1" type:"string"`
LastModified *time.Time `type:"timestamp"
timestampFormat:"iso8601"`
Owner *Owner `type:"structure"`
Size *int64 `type:"integer"`
StorageClass *string `type:"string" enum:"ObjectStorageClass"`
}
type ObjectIdentifier struct {
_ struct{} `type:"structure"`
Key *string `min:"1" type:"string" required:"true"`
VersionId *string `type:"string"`
}
objects := getObjects() // return []*s3.Object
a := make([]*s3.ObjectIdentifier, len(objects))
for i, v := range objects {
a[i].Key = v.Key
}
a[i].Key = v.Key 是错误的。
如何实现删除bucket/userID?
【问题讨论】:
标签: amazon-s3 aws-sdk aws-sdk-go