當前位置: 首頁>>代碼示例>>Golang>>正文


Golang rs.New函數代碼示例

本文整理匯總了Golang中github.com/qiniu/api/rs.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的github.com/qiniu/api/rs.New函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。