func BatchStat(client rs.Client, entries []rs.EntryPath) (ret []BatchItemRet, err error) { b := make([]string, len(entries)) for i, e := range entries { b[i] = rs.URIStat(e.Bucket, e.Key) } err = client.Batch(nil, &ret, b) return }
//高级批处理功能 func highBatch() { ops := []string{ rs.URIStat("needkane", "need"), rs.URICopy("needkane", "kane3.jpg", "needcrystal", "kane"), rs.URIDelete("needkane", "kane3.jpg"), } rets := new([]rs.BatchItemRet) var rsCli = rs.New(nil) err := rsCli.Batch(nil, rets, ops) if err != nil { log.Println("rs.Batch failed:", err) return } for time, ret := range *rets { log.Println(time, "::", ret.Code, ret.Error) } }
func batchDemo(bucket, key, bucket1, key1, bucket2, key2, bucket3, key3, bucket4, key4 string) { // @gist rsBatchPre // 此操作前 请确保 accesskey和secretkey 已被正确赋值 var rsCli = rs.New(nil) var err error // @endgist // @gist rsEntryPathes entryPathes := []rs.EntryPath{ rs.EntryPath{ Bucket: bucket1, Key: key1, }, rs.EntryPath{ Bucket: bucket2, Key: key2, }, } // @endgist // @gist rsPathPairs // 每个复制操作都含有源文件和目标文件 entryPairs := []rs.EntryPathPair{ rs.EntryPathPair{ Src: rs.EntryPath{ Bucket: bucket1, Key: key1, }, Dest: rs.EntryPath{ Bucket: bucket2, Key: key2, }, }, rs.EntryPathPair{ Src: rs.EntryPath{ Bucket: bucket3, Key: key3, }, Dest: rs.EntryPath{ Bucket: bucket4, Key: key4, }, }, } // @endgist // @gist rsBatchStat var batchStatRets []rs.BatchStatItemRet batchStatRets, err = rsCli.BatchStat(nil, entryPathes) // []rs.BatchStatItemRet, error if err != nil { // 产生错误 log.Println("rs.BatchStat failed:", err) return } // 处理返回值 for _, item := range batchStatRets { log.Println(item) } // @endgist // @gist rsBatchCopy var batchCopyRets []rs.BatchItemRet batchCopyRets, err = rsCli.BatchCopy(nil, entryPairs) if err != nil { // 产生错误 log.Println("rs.BatchCopy failed:", err) return } for _, item := range batchCopyRets { // 遍历每个操作的返回结果 log.Println(item.Code, item.Error) } // @endgist // @gist rsBatchMove var batchMoveRets []rs.BatchItemRet batchCopyRets, err = rsCli.BatchMove(nil, entryPairs) if err != nil { // 产生错误 log.Println("rs.BatchMove failed:", err) return } for _, item := range batchMoveRets { // 遍历每个操作的返回结果 log.Println(item.Code, item.Error) } // @endgist // @gist rsBatchDelete var batchDeleteRets []rs.BatchItemRet batchDeleteRets, err = rsCli.BatchDelete(nil, entryPathes) if err != nil { // 产生错误 log.Println("rs.BatchMove failed:", err) return } for _, item := range batchDeleteRets { // 遍历每个操作的返回结果 log.Println(item.Code, item.Error) } // @endgist // @gist rsBatchAdv ops := []string{ rs.URIStat(bucket, key1), rs.URICopy(bucket, key1, bucket, key2), // 复制key1到key2 rs.URIDelete(bucket, key1), // 删除key1 rs.URIMove(bucket, key2, bucket, key1), //将key2移动到key1 } rets := new([]rs.BatchItemRet) err = rsCli.Batch(nil, rets, ops) if err != nil { // 产生错误 log.Println("rs.Batch failed:", err) return } for _, ret := range *rets { log.Println(ret.Code, ret.Error) } // @endgist }