本文整理汇总了Golang中github.com/qiniu/api/rs.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestAll
func TestAll(t *testing.T) {
testPut(t, key1)
k1 := testPutWithoutKey(t)
testPutFile(t, localFile, key2)
k2 := testPutFileWithoutKey(t, localFile)
//clear all keys
rs.New(nil).Delete(nil, bucket, key1)
rs.New(nil).Delete(nil, bucket, key2)
rs.New(nil).Delete(nil, bucket, k1)
rs.New(nil).Delete(nil, bucket, k2)
}
开发者ID:BluntBlade,项目名称:api,代码行数:13,代码来源:io_api_test.go
示例2: testXVar
func testXVar(t *testing.T, token string, extra *PutExtra) {
type Ret struct {
PutRet
X1 string `json:"x:1"`
}
var ret Ret
f, err := os.Open(testFile)
if err != nil {
t.Fatal(err)
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
t.Fatal(err)
}
err = Put(nil, &ret, token, testKey, f, fi.Size(), extra)
if err != nil {
t.Fatal(err)
}
defer rs.New(nil).Delete(nil, bucket, ret.Key)
if ret.X1 != "1" {
t.Fatal("test xVar failed:", ret.X1)
}
}
开发者ID:kuguobing,项目名称:api,代码行数:28,代码来源:resumable_api_test.go
示例3: Copy
func Copy(cmd string, params ...string) {
if len(params) == 3 || len(params) == 4 {
srcBucket := params[0]
srcKey := params[1]
destBucket := params[2]
destKey := srcKey
if len(params) == 4 {
destKey = params[3]
}
accountS.Get()
mac := digest.Mac{
accountS.AccessKey,
[]byte(accountS.SecretKey),
}
client := rs.New(&mac)
err := client.Copy(nil, srcBucket, srcKey, destBucket, destKey)
if err != nil {
log.Error("Copy error,", err)
} else {
fmt.Println("Done!")
}
} else {
CmdHelp(cmd)
}
}
开发者ID:joozo-gexia,项目名称:qshell,代码行数:25,代码来源:rs.go
示例4: copy
func copy(keySrc, keyDest string) {
client := rs.New(mac)
err := client.Copy(nil, Bucket, keySrc, Bucket_Copy, keyDest)
if err != nil {
//产生错误
log.Println("rs.Copy failed:", err)
return
}
}
开发者ID:sugeladi,项目名称:goWeb,代码行数:9,代码来源:qiniu.go
示例5: copyFile
//6.3 copy file
func copyFile(bucketSrc string, keySrc string, bucketDest string, keyDest string) {
var rsCli = rs.New(nil)
err := rsCli.Copy(nil, bucketSrc, keySrc, bucketDest, keyDest)
if err != nil {
log.Println("rs.Copy failed :", err)
return
} else {
log.Println("copy success to:", bucketDest)
}
}
开发者ID:needkane,项目名称:qiniu,代码行数:11,代码来源:demo.go
示例6: qiniuDeleteImage
func qiniuDeleteImage(fileName string) error {
var client rs.Client
client = rs.New(nil)
err := client.Delete(nil, models.QiniuScope, fileName)
if err != nil {
revel.ERROR.Println("rs.Delete failed:", err)
}
return err
}
开发者ID:zeuson,项目名称:gorevel,代码行数:11,代码来源:application.go
示例7: getInfo
func getInfo(key string) {
var ret rs.Entry
client := rs.New(mac)
ret, err := client.Stat(nil, Bucket, key)
if err != nil {
//产生错误
log.Println("rs.Stat failed:", err)
return
}
//处理返回值
log.Printf("ret:%+v", ret)
}
开发者ID:sugeladi,项目名称:goWeb,代码行数:12,代码来源:qiniu.go
示例8: Fetch
func Fetch(mac *digest.Mac, remoteResUrl, bucket, key string) (fetchResult FetchResult, err error) {
client := rs.New(mac)
entry := bucket
if key != "" {
entry += ":" + key
}
fetchUri := fmt.Sprintf("/fetch/%s/to/%s",
base64.URLEncoding.EncodeToString([]byte(remoteResUrl)),
base64.URLEncoding.EncodeToString([]byte(entry)))
err = client.Conn.Call(nil, &fetchResult, conf.IO_HOST+fetchUri)
return
}
开发者ID:joozo-gexia,项目名称:qshell,代码行数:12,代码来源:rs.go
示例9: init
func init() {
ACCESS_KEY = os.Getenv("QINIU_ACCESS_KEY")
SECRET_KEY = os.Getenv("QINIU_SECRET_KEY")
if ACCESS_KEY == "" || SECRET_KEY == "" {
panic("require ACCESS_KEY & SECRET_KEY")
}
bucket = os.Getenv("QINIU_TEST_BUCKET")
if bucket == "" {
panic("require QINIU_TEST_BUCKET")
}
rs.New(nil).Delete(nil, bucket, testKey)
}
开发者ID:kuguobing,项目名称:api,代码行数:13,代码来源:resumable_api_test.go
示例10: delFile2
//5.2delete file
func delFile2() {
bucket := "need10"
key := "132"
var rsCli = rs.New(nil)
err := rsCli.Delete(nil, bucket, key)
if err != nil {
//generate error
log.Println("rs.Copy failed:", err)
return
} else {
log.Println("success delete:", key)
}
}
开发者ID:needkane,项目名称:qiniu,代码行数:15,代码来源:demo.go
示例11: batchDel
func batchDel(keys []string) {
entryPaths := []rs.EntryPath{}
for _, key := range keys {
ep := rs.EntryPath{
Bucket: Bucket,
Key: key,
}
entryPaths = append(entryPaths, ep)
}
client := rs.New(mac)
client.BatchDelete(nil, entryPaths)
}
开发者ID:sugeladi,项目名称:goWeb,代码行数:15,代码来源:qiniu.go
示例12: testPutFile
func testPutFile(t *testing.T, token string, extra *PutExtra) {
var ret PutRet
f, err := os.Open(testFile)
if err != nil {
t.Fatal(err)
}
defer f.Close()
err = PutFile(nil, &ret, token, testKey, testFile, extra)
if err != nil {
t.Fatal(err)
}
defer rs.New(nil).Delete(nil, bucket, ret.Key)
}
开发者ID:kuguobing,项目名称:api,代码行数:15,代码来源:resumable_api_test.go
示例13: DeleteFiles
// 批量删除文件
func (this *QiniuController) DeleteFiles(bucketSrc string, keySrc []string) bool {
entryPathes := make([]rs.EntryPath, len(keySrc))
// 赋值
for k, _ := range entryPathes {
entryPathes[k].Bucket = bucketSrc
entryPathes[k].Key = keySrc[k]
}
rsCli := rs.New(nil)
_, err := rsCli.BatchDelete(nil, entryPathes)
return err == nil
}
开发者ID:tzq668766,项目名称:avatar,代码行数:16,代码来源:qiniu.go
示例14: BatchCopy
func BatchCopy(cmd string, params ...string) {
if len(params) == 3 {
srcBucket := params[0]
destBucket := params[1]
srcDestKeyMapFile := params[2]
accountS.Get()
mac := digest.Mac{
accountS.AccessKey,
[]byte(accountS.SecretKey),
}
client := rs.New(&mac)
fp, err := os.Open(srcDestKeyMapFile)
if err != nil {
log.Error("Open src dest key map file error")
return
}
defer fp.Close()
scanner := bufio.NewScanner(fp)
scanner.Split(bufio.ScanLines)
entries := make([]qshell.CopyEntryPath, 0)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
items := strings.Split(line, "\t")
if len(items) == 1 || len(items) == 2 {
srcKey := items[0]
destKey := srcKey
if len(items) == 2 {
destKey = items[1]
}
if srcKey != "" && destKey != "" {
entry := qshell.CopyEntryPath{srcBucket, destBucket, srcKey, destKey}
entries = append(entries, entry)
}
}
if len(entries) == BATCH_ALLOW_MAX {
batchCopy(client, entries)
entries = make([]qshell.CopyEntryPath, 0)
}
}
if len(entries) > 0 {
batchCopy(client, entries)
}
fmt.Println("All Copyed!")
} else {
CmdHelp(cmd)
}
}
开发者ID:joozo-gexia,项目名称:qshell,代码行数:47,代码来源:rs.go
示例15: BatchDelete
func BatchDelete(cmd string, params ...string) {
if len(params) == 2 {
bucket := params[0]
keyListFile := params[1]
accountS.Get()
mac := digest.Mac{
accountS.AccessKey,
[]byte(accountS.SecretKey),
}
client := rs.New(&mac)
fp, err := os.Open(keyListFile)
if err != nil {
log.Error("Open key list file error", err)
return
}
defer fp.Close()
scanner := bufio.NewScanner(fp)
scanner.Split(bufio.ScanLines)
entries := make([]rs.EntryPath, 0)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
items := strings.Split(line, "\t")
if len(items) > 0 {
key := items[0]
if key != "" {
entry := rs.EntryPath{
bucket, key,
}
entries = append(entries, entry)
}
}
//check 1000 limit
if len(entries) == BATCH_ALLOW_MAX {
batchDelete(client, entries)
//reset slice
entries = make([]rs.EntryPath, 0)
}
}
//delete the last batch
if len(entries) > 0 {
batchDelete(client, entries)
}
fmt.Println("All deleted!")
} else {
CmdHelp(cmd)
}
}
开发者ID:joozo-gexia,项目名称:qshell,代码行数:47,代码来源:rs.go
示例16: rsDemo
func rsDemo(bucket, key, bucketSrc, keySrc, bucketDest, keyDest string) {
// @gist rsPre
//此操作前 请确保 accesskey和secretkey 已被正确赋值
var rsCli = rs.New(nil)
var err error
// @endgist
// @gist rsStat
var ret rs.Entry
ret, err = rsCli.Stat(nil, bucket, key)
if err != nil {
// 产生错误
log.Println("rs.Stat failed:", err)
return
}
// 处理返回值
log.Println(ret)
// @endgist
// @gist rsCopy
err = rsCli.Copy(nil, bucketSrc, keySrc, bucketDest, keyDest)
if err != nil {
// 产生错误
log.Println("rs.Copy failed:", err)
return
}
// @endgist
// @gist rsMove
err = rsCli.Move(nil, bucketSrc, keySrc, bucketDest, keyDest)
if err != nil {
//产生错误
log.Println("rs.Copy failed:", err)
return
}
// @endgist
// @gist rsDelete
err = rsCli.Delete(nil, bucket, key)
if err != nil {
// 产生错误
log.Println("rs.Copy failed:", err)
return
}
// @endgist
}
开发者ID:HYQMartin,项目名称:star,代码行数:47,代码来源:rs.go
示例17: highBatch
//高级批处理功能
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)
}
}
开发者ID:needkane,项目名称:qiniu,代码行数:18,代码来源:demo.go
示例18: Run
func (t *Task) Run() {
urls, err := UrlsToSync(t.SyncSrc)
if err != nil {
log.Error("Read Urls Failed:", err)
return
}
cl, base, err := t.Synced()
if err != nil {
log.Error("Read Log Failed", err)
return
}
left := namediff.Diff(urls, base)
mac := digest.Mac{
AccessKey: t.Ak,
SecretKey: []byte(t.Sk),
}
log.Info("Entry Fetched:", len(base))
log.Info("Entry ALL:", len(urls))
log.Info("Entry TO Fetch:", len(left))
c := rs.New(&mac)
failed := 0
for i := 0; i < len(left); i++ {
urlSrc := t.srcUrl(left[i])
key := destKey(left[i])
err := c.Fetch(nil, urlSrc, t.Bucket, key)
if err != nil {
log.Error("Fetch Url Failed:", err, urlSrc)
failed++
continue
}
cl.Put(left[i])
log.Info(urlSrc, "==>", t.Bucket, key)
}
if failed == 0 {
log.Info("Fetch Success")
} else {
log.Info(failed, "Files Failed")
}
return
}
开发者ID:rwifeng,项目名称:qiniutools,代码行数:44,代码来源:fetch.go
示例19: BatchRename
func BatchRename(cmd string, params ...string) {
if len(params) == 2 {
bucket := params[0]
oldNewKeyMapFile := params[1]
accountS.Get()
mac := digest.Mac{
accountS.AccessKey,
[]byte(accountS.SecretKey),
}
client := rs.New(&mac)
fp, err := os.Open(oldNewKeyMapFile)
if err != nil {
log.Error("Open old new key map file error")
return
}
defer fp.Close()
scanner := bufio.NewScanner(fp)
scanner.Split(bufio.ScanLines)
entries := make([]qshell.RenameEntryPath, 0)
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
items := strings.Split(line, "\t")
if len(items) == 2 {
oldKey := items[0]
newKey := items[1]
if oldKey != "" && newKey != "" {
entry := qshell.RenameEntryPath{bucket, oldKey, newKey}
entries = append(entries, entry)
}
}
if len(entries) == BATCH_ALLOW_MAX {
batchRename(client, entries)
entries = make([]qshell.RenameEntryPath, 0)
}
}
if len(entries) > 0 {
batchRename(client, entries)
}
fmt.Println("All Renamed!")
} else {
CmdHelp(cmd)
}
}
开发者ID:joozo-gexia,项目名称:qshell,代码行数:43,代码来源:rs.go
示例20: M3u8Delete
func M3u8Delete(cmd string, params ...string) {
if len(params) == 2 || len(params) == 3 {
bucket := params[0]
m3u8Key := params[1]
isPrivate := false
if len(params) == 3 {
isPrivate, _ = strconv.ParseBool(params[2])
}
accountS.Get()
mac := digest.Mac{
accountS.AccessKey,
[]byte(accountS.SecretKey),
}
m3u8FileList, err := qshell.M3u8FileList(&mac, bucket, m3u8Key, isPrivate)
if err != nil {
log.Error(err)
return
}
client := rs.New(&mac)
entryCnt := len(m3u8FileList)
if entryCnt == 0 {
log.Error("no m3u8 slices found")
return
}
if entryCnt <= BATCH_ALLOW_MAX {
batchDelete(client, m3u8FileList)
} else {
batchCnt := entryCnt / BATCH_ALLOW_MAX
for i := 0; i < batchCnt; i++ {
end := (i + 1) * BATCH_ALLOW_MAX
if end > entryCnt {
end = entryCnt
}
entriesToDelete := m3u8FileList[i*BATCH_ALLOW_MAX : end]
batchDelete(client, entriesToDelete)
}
}
fmt.Println("All deleted!")
} else {
CmdHelp(cmd)
}
}
开发者ID:joozo-gexia,项目名称:qshell,代码行数:42,代码来源:rs.go
注:本文中的github.com/qiniu/api/rs.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论