做个记录
package main
import (
"fmt"
qiniuConf "github.com/qiniu/api/conf"
qiniuRs "github.com/qiniu/api/rs"
qiniuRsf "github.com/qiniu/api/rsf"
qiniuRpc "github.com/qiniu/rpc"
"io"
)
const (
BUCKET = "xxx"
ACCESS_KEY = "xxxxxxxxxxxx"
SECRET_KEY = "xxxxxxxxxxxx"
)
func main() {
qiniuConf.ACCESS_KEY = ACCESS_KEY
qiniuConf.SECRET_KEY = SECRET_KEY
var entities []qiniuRsf.ListItem
var err error
var l qiniuRpc.Logger
marker := ""
rsf := qiniuRsf.New(nil)
for err == nil {
entities, marker, err = rsf.ListPrefix(l, BUCKET, "", marker, 1000)
for _, item := range entities {
fmt.Println("item:", item)
}
}
if err != io.EOF {
fmt.Println("list all failed:", err)
}
if 0 == len(entities) {
return
}
entityPathes := make([]qiniuRs.EntryPath, 0)
for _, v := range entities {
entity := qiniuRs.EntryPath{
Bucket: BUCKET,
Key: v.Key,
}
entityPathes = append(entityPathes, entity)
}
var batchDeleteRets []qiniuRs.BatchItemRet
rs := qiniuRs.New(nil)
batchDeleteRets, err = rs.BatchDelete(nil, entityPathes)
if err != nil {
fmt.Println("rs.batchdelete.error:", err)
return
}
for _, item := range batchDeleteRets {
fmt.Println(item.Code, item.Error)
}
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
有疑问加站长微信联系(非本文作者)