官网看api,如何使用,对于第一次使用go语言的我略显吃力,嘿嘿,看了个demo就会了,而且超简单
package main
//delFile()
//delFile2()
//imageAttr2()
//copyFile("needkane", "need", "needcrystal", "needtoo")
//fmt.Println(downloadUrl("needcrystal.qiniudn.com", "needtoo"))
//getBatchInfo()
//highBatch()
//println(makeViewUrl("http://needkane.qiniudn.com/need"))
var rc = rsf.New(nil)//这里注意我这传入类型rsf.Client,而sdk写的是引用*rsf.Client;若采用sdk的形式,则调用传参数时应该是listAll(nil,&rc,"needkane","nee")
listAll(nil, rc, "needkane", "nee")
}
//批量查询操作
func getBatchInfo() {
entryPathes := []rs.EntryPath{
rs.EntryPath{
Bucket: "needkane",
Key: "kane3.jpg",
},
rs.EntryPath{
Bucket: "needcrystal",
Key: "needtoo",
},
}
var batchStatRests []rs.BatchStatItemRet
var rsCli = rs.New(nil)
batchStatRests, err := rsCli.BatchStat(nil, entryPathes)
if err != nil {
log.Println("rs.BatchStat failed", err)
return
}
for time, item := range batchStatRests {
log.Println(time, ";;;;", item)
}
}
//联合多种批处理
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 makeViewUrl(imageUrl string) string {
/* var view = fop.ImageView{
//Mode int // 缩略模式
Width: 1000, // Width = 0 表示不限定宽度
Height: 1200, // Height = 0 表示不限定高度
Quality: 100, // 质量, 1-100
Format: "gif", // 输出格式,如jpg, gif, png, tif等等
}*/
var view = fop.ImageView{}
view.Height = 100
view.Width = 500
view.Quality = 100
return view.MakeRequest(imageUrl)
}
//
func listAll(l rpc.Logger, rc rsf.Client, bucketName string, prefix string) {
var entries []rsf.ListItem
var marker = ""
var err error
var limit = 1000
for err == nil {
entries, marker, err = rc.ListPrefix(nil, bucketName, prefix, marker, limit)
for _, item := range entries {
log.Print("item:", item)
}
}
if err != io.EOF {
//非预期的错误
log.Print("listAll failed:", err)
}
}
有个响应迟钝的bug,这里调用了api,但是图形界面上没有显示调用的次数