本文整理汇总了Golang中github.com/qiniu/api/v6/rs.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
}
示例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
}
示例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)
}
}
示例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)
}
}
示例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
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
}
示例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
}
示例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)
}
}
示例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)
}
}
示例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}
}
示例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)
}
}
示例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)
}
}