• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang rs.New函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/qiniu/api/v6/rs.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了New函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: 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:jango2015,项目名称:api.v6,代码行数:28,代码来源:resumable_api_test.go


示例2: GetBuckets

func GetBuckets(mac *digest.Mac) (buckets []string, err error) {
	buckets = make([]string, 0)
	client := rs.New(mac)
	bucketsUri := fmt.Sprintf("%s/buckets", conf.RS_HOST)
	err = client.Conn.Call(nil, &buckets, bucketsUri)
	return
}
开发者ID:jbasttdi,项目名称:qshell,代码行数:7,代码来源:bucket.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:micooz,项目名称:qshell,代码行数:25,代码来源:rs.go


示例4: BatchRename

func BatchRename(cmd string, params ...string) {
	//confirm
	rcode := CreateRandString(6)
	if rcode == "" {
		log.Error("Create confirm code failed")
		return
	}

	rcode2 := ""
	fmt.Print(fmt.Sprintf("\033[31m<DANGER>\033[0m Input \033[32m%s\033[0m to confirm operation: ", rcode))
	fmt.Scanln(&rcode2)

	if rcode != rcode2 {
		fmt.Println("Task quit!")
		return
	}

	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:micooz,项目名称:qshell,代码行数:59,代码来源:rs.go


示例5: GetDomainsOfBucket

func GetDomainsOfBucket(mac *digest.Mac, bucket string) (domains []string, err error) {
	domains = make([]string, 0)
	client := rs.New(mac)
	getDomainsUrl := "http://api.qiniu.com/v6/domain/list"
	postData := map[string][]string{
		"tbl": []string{bucket},
	}
	err = client.Conn.CallWithForm(nil, &domains, getDomainsUrl, postData)
	return
}
开发者ID:jbasttdi,项目名称:qshell,代码行数:10,代码来源:bucket.go


示例6: 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:jbasttdi,项目名称:qshell,代码行数:12,代码来源:rs.go


示例7: 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:jango2015,项目名称:api.v6,代码行数:13,代码来源:resumable_api_test.go


示例8: 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:jango2015,项目名称:api.v6,代码行数:15,代码来源:resumable_api_test.go


示例9: 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:jbasttdi,项目名称:qshell,代码行数:47,代码来源:rs.go


示例10: 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:jango2015,项目名称:api.v6,代码行数:47,代码来源:rs.go


示例11: 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:jbasttdi,项目名称:qshell,代码行数:47,代码来源:rs.go


示例12: 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:jbasttdi,项目名称:qshell,代码行数:43,代码来源:rs.go


示例13: DeleteHandlers

func DeleteHandlers() []martini.Handler {
	var bind = binding.Bind(DeleteReqData{})
	var deleteHandler = func(data DeleteReqData, w http.ResponseWriter) {
		index := strings.LastIndex(data.Url, "/")
		runes := []rune(data.Url)
		key := string(runes[index+1:])
		bucket, err := bucketdb.FindByName(data.Bucket)
		rsCli := rs.New(&digest.Mac{bucket.Ak, []byte(bucket.Sk)})
		err = rsCli.Delete(nil, bucket.Name, key)
		if err != nil {
			//产生错误
			glog.Infoln("删除图片错误:", err)
			io.WriteString(w, data.Callback+"({error:1})")
			return
		}
		io.WriteString(w, data.Callback+"({error:0})")
	}
	return []martini.Handler{bind, deleteHandler}
}
开发者ID:empirefox,项目名称:iniu-old,代码行数:19,代码来源:kindeditor.go


示例14: 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:micooz,项目名称:qshell,代码行数:42,代码来源:rs.go


示例15: Stat

func Stat(cmd string, params ...string) {
	if len(params) == 2 {
		bucket := params[0]
		key := params[1]
		accountS.Get()
		mac := digest.Mac{
			accountS.AccessKey,
			[]byte(accountS.SecretKey),
		}
		client := rs.New(&mac)
		entry, err := client.Stat(nil, bucket, key)
		if err != nil {
			log.Error("Stat error,", err)
		} else {
			printStat(bucket, key, entry)
		}
	} else {
		CmdHelp(cmd)
	}
}
开发者ID:micooz,项目名称:qshell,代码行数:20,代码来源:rs.go


示例16: TestAll

func TestAll(t *testing.T) {

	//先上传文件到空间做初始化准备
	for i := 0; i < 10; i++ {
		key := "rsf_test_put_" + strconv.Itoa(i)
		err := upFile("rsf_api.go", bucketName, key)
		if err != nil {
			t.Fatal(err)
		}
		keys = append(keys, key)
	}
	defer func() {
		for _, k := range keys {
			rs.New(nil).Delete(nil, bucketName, k)
		}
	}()

	testList(t)
	testEof(t)
}
开发者ID:jango2015,项目名称:api.v6,代码行数:20,代码来源:rsf_api_test.go


示例17: DeleteFile

func DeleteFile(fileName string) bool {
	entryPathes := []qrs.EntryPath{
		qrs.EntryPath{
			Bucket: BulketName,
			Key:    fmt.Sprintf("%s.html", fileName),
		},
		qrs.EntryPath{
			Bucket: BulketName,
			Key:    fmt.Sprintf("%s_code.html", fileName),
		},
	}
	rs := qrs.New(nil)
	_, err := rs.BatchDelete(nil, entryPathes)
	if err != nil {
		//产生错误
		revel.ERROR.Printf("rs.BatchMove failed:%v", err)
		return false
	}
	return true
}
开发者ID:joveth,项目名称:isaac_web,代码行数:20,代码来源:qiniutool.go


示例18: Delete

func Delete(cmd string, params ...string) {
	if len(params) == 2 {
		bucket := params[0]
		key := params[1]
		accountS.Get()
		mac := digest.Mac{
			accountS.AccessKey,
			[]byte(accountS.SecretKey),
		}
		client := rs.New(&mac)
		err := client.Delete(nil, bucket, key)
		if err != nil {
			log.Error("Delete error,", err)
		} else {
			fmt.Println("Done!")
		}
	} else {
		CmdHelp(cmd)
	}
}
开发者ID:micooz,项目名称:qshell,代码行数:20,代码来源:rs.go


示例19: testPutWithoutKey

func testPutWithoutKey(t *testing.T, token string, extra *PutExtra) {

	var ret PutRet
	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 = PutWithoutKey(nil, &ret, token, f, fi.Size(), extra)
	if err != nil {
		t.Fatal(err)
	}
	defer rs.New(nil).Delete(nil, bucket, ret.Key)
}
开发者ID:jango2015,项目名称:api.v6,代码行数:20,代码来源:resumable_api_test.go


示例20: Chgm

func Chgm(cmd string, params ...string) {
	if len(params) == 3 {
		bucket := params[0]
		key := params[1]
		newMimeType := params[2]
		accountS.Get()
		mac := digest.Mac{
			accountS.AccessKey,
			[]byte(accountS.SecretKey),
		}
		client := rs.New(&mac)
		err := client.ChangeMime(nil, bucket, key, newMimeType)
		if err != nil {
			log.Error("Change mimeType error,", err)
		} else {
			fmt.Println("Done!")
		}
	} else {
		CmdHelp(cmd)
	}
}
开发者ID:micooz,项目名称:qshell,代码行数:21,代码来源:rs.go



注:本文中的github.com/qiniu/api/v6/rs.New函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang rs.PutPolicy类代码示例发布时间:2022-05-28
下一篇:
Golang rs.PutPolicy类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap