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

Golang log.Error函数代码示例

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

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



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

示例1: Base64Decode

func Base64Decode(cmd string, params ...string) {
	if len(params) == 1 || len(params) == 2 {
		urlSafe := true
		var err error
		var dataToDecode string
		if len(params) == 2 {
			urlSafe, err = strconv.ParseBool(params[0])
			if err != nil {
				log.Error("Invalid bool value or <UrlSafe>, must true or false")
				return
			}
			dataToDecode = params[1]
		} else {
			dataToDecode = params[0]
		}
		var dataDecoded []byte
		if urlSafe {
			dataDecoded, err = base64.URLEncoding.DecodeString(dataToDecode)
			if err != nil {
				log.Error("Failed to decode `", dataToDecode, "' in url safe mode.")
				return
			}
		} else {
			dataDecoded, err = base64.StdEncoding.DecodeString(dataToDecode)
			if err != nil {
				log.Error("Failed to decode `", dataToDecode, "' in standard mode.")
				return
			}
		}
		fmt.Println(string(dataDecoded))
	} else {
		CmdHelp(cmd)
	}
}
开发者ID:micooz,项目名称:qshell,代码行数:34,代码来源:utils.go


示例2: main

func main() {
	if len(os.Args) < 2 {
		fmt.Println("qrsb <dir>")
		os.Exit(1)
	}
	p, err := NewRsf(os.Args[1])
	if err != nil {
		log.Error("err:", err)
		os.Exit(2)
	}
	if p.isFirstRun() {
		p.firstRun()
	}
	// check pos
	pos := Pos{}
	err = loadJsonFile(&pos, p.baseDir+"/qrsb.pos")
	// pos.Marker = "" //置空,重新开始
	if err != nil {
		log.Error("err:load qrsb.pos file failed,ABORT!")
		os.Exit(2)
	}
	err = p.Run(&pos)
	if err != nil {
		log.Error("err:", err)
		p.printResult()
		os.Exit(2)
	}
	log.Info("Done!")
	p.printResult()
	return
}
开发者ID:rwifeng,项目名称:qiniutools,代码行数:31,代码来源:main.go


示例3: GetStream

func GetStream(sessionId, accessToken string, gResult *GetStreamResult) {
	userId, valid := CheckAuthValid(sessionId, accessToken, &gResult.ApiResult)
	if !valid {
		return
	}

	//get stream by user
	streamId, gErr := model.GetStreamIdOfUser(userId)
	if gErr != nil {
		gResult.SetCode(API_SERVER_ERROR)
		return
	}

	if streamId == "" {
		newStreamId, newStreamData, newStreamErr := pilis.CreateDynamicStream()
		if newStreamErr != nil {
			gResult.SetCode(API_SERVER_ERROR)
			return
		}
		//update user stream
		sErr := model.SetStreamIdOfUser(userId, newStreamId)
		if sErr != nil {
			gResult.SetCode(API_SERVER_ERROR)
			return
		}
		gResult.StreamId = streamId
		gResult.Stream = newStreamData
	} else {
		streamData, sCode, sErr := pilis.GetStream(streamId)
		if sErr != nil {
			if sCode == 404 {
				//the stream is recycled, try to create a new one
				newStreamId, newStreamData, newStreamErr := pilis.CreateDynamicStream()
				if newStreamErr != nil {
					log.Error(newStreamErr)
					gResult.SetCode(API_SERVER_ERROR)
					return
				}
				//update user stream
				sErr := model.SetStreamIdOfUser(userId, newStreamId)
				if sErr != nil {
					log.Error(sErr)
					gResult.SetCode(API_SERVER_ERROR)
					return
				}
				gResult.StreamId = streamId
				gResult.Stream = newStreamData
			} else {
				log.Error(sErr)
				gResult.SetCode(API_SERVER_ERROR)
				return
			}
		}
		gResult.StreamId = streamId
		gResult.Stream = streamData
	}

	gResult.SetOk()
	return
}
开发者ID:qiniudemo,项目名称:qiniu-live-server,代码行数:60,代码来源:stream_service.go


示例4: download

//下载文件item.Name
//retry:重试次数
func (p *Rsf) download(item rsf.DumpItem, retry int) (err error) {
	log.Info("downloading file :", item.Name, " ,file size = ", item.Fsize, "bytes")
	for i := 1; i <= retry; i++ {
		code, err := p.getFile(item.Name)
		if err == nil {
			log.Info("download completed!")
			return nil
		}
		log.Error("getFile err:", code, err)
		if code == 612 {
			break
		}
		log.Error("retry download ", item.Name, " ", i, " times")
		time.Sleep(SLEEP_TIME)

	}
	//重试retry次后,下载失败
	ffail, err := os.OpenFile(p.baseDir+"/qrsb.failkeys", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0660)
	if err == nil {
		defer ffail.Close()
		b, err := json.Marshal(item)
		if err == nil {
			ffail.WriteString(string(b))
		}
	} else {
		log.Error("Open qrsb.failkeys err")
		return err
	}
	return
}
开发者ID:rwifeng,项目名称:qiniutools,代码行数:32,代码来源:main.go


示例5: ReqId

func ReqId(cmd string, params ...string) {
	if len(params) == 1 {
		reqId := params[0]
		decodedBytes, err := base64.URLEncoding.DecodeString(reqId)
		if err != nil || len(decodedBytes) < 4 {
			log.Error("Invalid reqid", reqId, err)
			return
		}

		newBytes := decodedBytes[4:]
		newBytesLen := len(newBytes)
		newStr := ""
		for i := newBytesLen - 1; i >= 0; i-- {
			newStr += fmt.Sprintf("%02X", newBytes[i])
		}
		unixNano, err := strconv.ParseInt(newStr, 16, 64)
		if err != nil {
			log.Error("Invalid reqid", reqId, err)
			return
		}
		dstDate := time.Unix(0, unixNano)
		fmt.Println(fmt.Sprintf("%04d-%02d-%02d/%02d-%02d", dstDate.Year(), dstDate.Month(), dstDate.Day(),
			dstDate.Hour(), dstDate.Minute()))
	} else {
		CmdHelp(cmd)
	}
}
开发者ID:micooz,项目名称:qshell,代码行数:27,代码来源:utils.go


示例6: 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


示例7: ResumablePut

func ResumablePut(cmd string, params ...string) {
	if len(params) == 3 || len(params) == 4 || len(params) == 5 {
		bucket := params[0]
		key := params[1]
		localFile := params[2]
		mimeType := ""
		upHost := "http://upload.qiniu.com"
		if len(params) == 4 {
			param := params[3]
			if strings.HasPrefix(param, "http") {
				upHost = param
			} else {
				mimeType = param
			}
		}
		if len(params) == 5 {
			mimeType = params[3]
			upHost = params[4]
		}
		accountS.Get()
		mac := digest.Mac{accountS.AccessKey, []byte(accountS.SecretKey)}
		policy := rs.PutPolicy{}
		policy.Scope = bucket
		putExtra := rio.PutExtra{}
		if mimeType != "" {
			putExtra.MimeType = mimeType
		}
		conf.UP_HOST = upHost
		progressHandler := ProgressHandler{
			BlockIndices:    make([]int, 0),
			BlockProgresses: make(map[int]float32),
		}
		putExtra.Notify = progressHandler.Notify
		putExtra.NotifyErr = progressHandler.NotifyErr
		uptoken := policy.Token(&mac)
		putRet := rio.PutRet{}
		startTime := time.Now()
		fStat, statErr := os.Stat(localFile)
		if statErr != nil {
			log.Error("Local file error", statErr)
			return
		}
		fsize := fStat.Size()
		err := rio.PutFile(nil, &putRet, uptoken, key, localFile, &putExtra)
		if err != nil {
			log.Error("Put file error", err)
		} else {
			fmt.Println("\r\nPut file", localFile, "=>", bucket, ":", putRet.Key, "(", putRet.Hash, ")", "success!")
		}
		lastNano := time.Now().UnixNano() - startTime.UnixNano()
		lastTime := fmt.Sprintf("%.2f", float32(lastNano)/1e9)
		avgSpeed := fmt.Sprintf("%.1f", float32(fsize)*1e6/float32(lastNano))
		fmt.Println("Last time:", lastTime, "s, Average Speed:", avgSpeed, "KB/s")
	} else {
		CmdHelp(cmd)
	}
}
开发者ID:joozo-gexia,项目名称:qshell,代码行数:57,代码来源:putfile.go


示例8: List

func (this *ListBucket) List(bucket string, prefix string, listResultFile string) (retErr error) {
	fp, openErr := os.OpenFile(listResultFile, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0666)
	if openErr != nil {
		retErr = openErr
		log.Error(fmt.Sprintf("Failed to open list result file `%s'", listResultFile))
		return
	}
	defer fp.Close()
	bw := bufio.NewWriter(fp)

	mac := digest.Mac{this.AccessKey, []byte(this.SecretKey)}
	client := rsf.New(&mac)
	marker := ""
	limit := 1000
	run := true
	maxRetryTimes := 5
	retryTimes := 1
	for run {
		entries, markerOut, err := client.ListPrefix(nil, bucket, prefix, marker, limit)
		if err != nil {
			if err == io.EOF {
				run = false
			} else {
				log.Error(fmt.Sprintf("List error for marker `%s'", marker), err)
				if retryTimes <= maxRetryTimes {
					log.Debug(fmt.Sprintf("Retry list for marker `%s' for `%d' time", marker, retryTimes))
					retryTimes += 1
					continue
				} else {
					log.Error(fmt.Sprintf("List failed too many times for `%s'", marker))
					break
				}
			}
		} else {
			retryTimes = 1
			if markerOut == "" {
				run = false
			} else {
				marker = markerOut
			}
		}
		//append entries
		for _, entry := range entries {
			lineData := fmt.Sprintf("%s\t%d\t%s\t%d\t%s\t%s\r\n", entry.Key, entry.Fsize, entry.Hash, entry.PutTime, entry.MimeType, entry.EndUser)
			_, wErr := bw.WriteString(lineData)
			if wErr != nil {
				log.Error(fmt.Sprintf("Write line data `%s' to list result file failed.", lineData))
			}
		}
		fErr := bw.Flush()
		if fErr != nil {
			log.Error("Flush data to list result file error", err)
		}
	}
	return
}
开发者ID:jbasttdi,项目名称:qshell,代码行数:56,代码来源:list_bucket.go


示例9: ListBucket

func (this *AliListBucket) ListBucket(listResultFile string) (err error) {
	//open result file
	mode := os.O_CREATE | os.O_TRUNC | os.O_WRONLY
	fp, openErr := os.OpenFile(listResultFile, mode, 0666)
	if openErr != nil {
		err = openErr
		return
	}
	defer fp.Close()
	bw := bufio.NewWriter(fp)
	//list bucket by prefix
	marker := ""
	prefixLen := len(this.Prefix)
	ossClient := oss.NewClient(this.DataCenter, this.AccessKeyId, this.AccessKeySecret, 0)
	maxRetryTimes := 5
	retryTimes := 1
	for {
		lbr, lbrErr := ossClient.GetBucket(this.Bucket, this.Prefix, marker, "", "")
		if lbrErr != nil {
			err = lbrErr
			log.Error("Parse list result error, ", "marker=[", marker, "]", lbrErr)
			if retryTimes <= maxRetryTimes {
				log.Debug("Retry marker=", marker, "] for ", retryTimes, "time...")
				retryTimes += 1
				continue
			} else {
				break
			}
		} else {
			retryTimes = 1
		}
		for _, object := range lbr.Contents {
			lmdTime, lmdPErr := time.Parse("2006-01-02T15:04:05.999Z", object.LastModified)
			if lmdPErr != nil {
				log.Error("Parse object last modified error, ", lmdPErr)
				lmdTime = time.Now()
			}
			bw.WriteString(fmt.Sprintln(fmt.Sprintf("%s\t%d\t%d", object.Key[prefixLen:], object.Size, lmdTime.UnixNano()/100)))
		}
		if !lbr.IsTruncated {
			break
		}
		marker = lbr.NextMarker
	}
	fErr := bw.Flush()
	if fErr != nil {
		log.Error("Write data to buffer writer failed", fErr)
		err = fErr
		return
	}
	return err
}
开发者ID:joozo-gexia,项目名称:qshell,代码行数:52,代码来源:alioss_list_bucket.go


示例10: loadJsonFile

func loadJsonFile(i interface{}, file string) error {
	d, err := ioutil.ReadFile(file)
	if err != nil {
		log.Error("load json file", file, "err:", err)
		return err
	}
	err = json.Unmarshal(d, i)
	if err != nil {
		log.Error("unmarshal json file", file, "err:", err)
		return err
	}
	return nil
}
开发者ID:rwifeng,项目名称:qiniutools,代码行数:13,代码来源:main.go


示例11: SendQueue

func SendQueue(queue string, content string) {

	beanstalkd, err := lentil.Dial(Config.Genral.BeanstalkServer)
	if err != nil {
		log.Error(err)
	} else {
		err = beanstalkd.Use(queue)
	}
	if err != nil {
		log.Error(err)
	} else {
		beanstalkd.Put(0, 0, 30, []byte(content))
	}
}
开发者ID:millken,项目名称:ydaemon,代码行数:14,代码来源:queue.go


示例12: writeJsonResult

func writeJsonResult(w http.ResponseWriter, statusCode int, result interface{}) {
	w.Header().Set("Content-Type", "application/json")
	w.WriteHeader(statusCode)
	data, err := json.Marshal(result)
	if err != nil {
		log.Error("encode ufop result error,", err)
		writeJsonError(w, 500, "encode ufop result error")
	} else {
		_, err := io.WriteString(w, string(data))
		if err != nil {
			log.Error("write json response error", err)
		}
	}
}
开发者ID:liuyanghejerry,项目名称:jerry-ufoptest,代码行数:14,代码来源:server.go


示例13: main

func main() {
	log.SetOutput(os.Stdout)
	setQiniuHosts()

	args := os.Args
	argc := len(args)

	var configFilePath string

	switch argc {
	case 2:
		configFilePath = args[1]
	default:
		help()
		return
	}

	//load config
	ufopConf := &ufop.UfopConfig{}
	confErr := ufopConf.LoadFromFile(configFilePath)
	if confErr != nil {
		log.Error("load config file error,", confErr)
		return
	}

	ufopServ := ufop.NewServer(ufopConf)

	//register job handlers
	if err := ufopServ.RegisterJobHandler("amerge.conf", &amerge.AudioMerger{}); err != nil {
		log.Error(err)
	}

	if err := ufopServ.RegisterJobHandler("html2image.conf", &html2image.Html2Imager{}); err != nil {
		log.Error(err)
	}

	if err := ufopServ.RegisterJobHandler("html2pdf.conf", &html2pdf.Html2Pdfer{}); err != nil {
		log.Error(err)
	}

	if err := ufopServ.RegisterJobHandler("mkzip.conf", &mkzip.Mkzipper{}); err != nil {
		log.Error(err)
	}

	if err := ufopServ.RegisterJobHandler("unzip.conf", &unzip.Unzipper{}); err != nil {
		log.Error(err)
	}

	if err := ufopServ.RegisterJobHandler("imagecomp.conf", &imagecomp.ImageComposer{}); err != nil {
		log.Error(err)
	}

	if err := ufopServ.RegisterJobHandler("roundpic.conf", &roundpic.RoundPicer{}); err != nil {
		log.Error(err)
	}

	//listen
	ufopServ.Listen()
}
开发者ID:songfei9315,项目名称:qiniu-ufop-service,代码行数:59,代码来源:qufop.go


示例14: Cache

func (this *DirCache) Cache(cacheRootPath string, cacheResultFile string) (fileCount int) {
	if _, err := os.Stat(cacheResultFile); err != nil {
		log.Debug(fmt.Sprintf("No cache file `%s' found, will create one", cacheResultFile))
	} else {
		os.Remove(cacheResultFile + ".old")
		if rErr := os.Rename(cacheResultFile, cacheResultFile+".old"); rErr != nil {
			log.Error(fmt.Sprintf("Unable to rename cache file, plz manually delete `%s' and `%s.old'",
				cacheResultFile, cacheResultFile))
			log.Error(rErr)
			return
		}
	}
	cacheResultFileH, err := os.OpenFile(cacheResultFile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666)
	if err != nil {
		log.Error(fmt.Sprintf("Failed to open cache file `%s'", cacheResultFile))
		return
	}
	defer cacheResultFileH.Close()
	bWriter := bufio.NewWriter(cacheResultFileH)
	walkStart := time.Now()
	log.Debug(fmt.Sprintf("Walk `%s' start from `%s'", cacheRootPath, walkStart.String()))
	log.Debug(fmt.Sprintf("Save dir cache result to `%s' and may take some time...", cacheResultFile))
	filepath.Walk(cacheRootPath, func(path string, fi os.FileInfo, err error) error {
		var retErr error
		log.Debug(fmt.Sprintf("Walking through `%s'", cacheRootPath))
		if !fi.IsDir() {
			relPath := strings.TrimPrefix(strings.TrimPrefix(path, cacheRootPath), string(os.PathSeparator))
			fsize := fi.Size()
			//Unit is 100ns
			flmd := fi.ModTime().UnixNano() / 100
			log.Debug(fmt.Sprintf("Hit file `%s' size: `%d' mode time: `%d`", relPath, fsize, flmd))
			fmeta := fmt.Sprintln(fmt.Sprintf("%s\t%d\t%d", relPath, fsize, flmd))
			if _, err := bWriter.WriteString(fmeta); err != nil {
				log.Error(fmt.Sprintf("Failed to write data `%s' to cache file", fmeta))
				retErr = err
			}
			fileCount += 1
		}
		return retErr
	})
	if err := bWriter.Flush(); err != nil {
		log.Error(fmt.Sprintf("Failed to flush to cache file `%s'", cacheResultFile))
	}

	walkEnd := time.Now()
	log.Debug(fmt.Sprintf("Walk `%s' end at `%s'", cacheRootPath, walkEnd.String()))
	log.Debug(fmt.Sprintf("Walk `%s' last for `%s'", cacheRootPath, time.Since(walkStart)))
	return
}
开发者ID:joozo-gexia,项目名称:qshell,代码行数:49,代码来源:dir_cache.go


示例15: batchRename

func batchRename(client rs.Client, entries []qshell.RenameEntryPath) {
	ret, err := qshell.BatchRename(client, entries)
	if err != nil {
		log.Error("Batch rename error", err)
	}
	if len(ret) > 0 {
		for i, entry := range entries {
			item := ret[i]
			if item.Data.Error != "" {
				log.Error(fmt.Sprintf("Rename '%s' => '%s' Failed, Code :%d", entry.OldKey, entry.NewKey, item.Code))
			} else {
				log.Debug(fmt.Sprintf("Rename '%s' => '%s' Success, Code :%d", entry.OldKey, entry.NewKey, item.Code))
			}
		}
	}
}
开发者ID:micooz,项目名称:qshell,代码行数:16,代码来源:rs.go


示例16: batchChgm

func batchChgm(client rs.Client, entries []qshell.ChgmEntryPath) {
	ret, err := qshell.BatchChgm(client, entries)
	if err != nil {
		log.Error("Batch chgm error", err)
	}
	if len(ret) > 0 {
		for i, entry := range entries {
			item := ret[i]
			if item.Data.Error != "" {
				log.Error(fmt.Sprintf("Chgm '%s' => '%s' Failed, Code :%d", entry.Key, entry.MimeType, item.Code))
			} else {
				log.Debug(fmt.Sprintf("Chgm '%s' => '%s' Success, Code :%d", entry.Key, entry.MimeType, item.Code))
			}
		}
	}
}
开发者ID:micooz,项目名称:qshell,代码行数:16,代码来源:rs.go


示例17: 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


示例18: QiniuUpload

func QiniuUpload(cmd string, params ...string) {
	if len(params) == 1 || len(params) == 2 {
		var uploadConfigFile string
		var threadCount int64
		var err error
		if len(params) == 2 {
			threadCount, err = strconv.ParseInt(params[0], 10, 64)
			if err != nil {
				log.Error("Invalid <ThreadCount> value,", params[0])
				return
			}
			uploadConfigFile = params[1]
		} else {
			uploadConfigFile = params[0]
		}
		if threadCount < qshell.MIN_UPLOAD_THREAD_COUNT ||
			threadCount > qshell.MAX_UPLOAD_THREAD_COUNT {
			log.Info("You can set <ThreadCount> value between 1 and 100 to improve speed")
			threadCount = qshell.MIN_UPLOAD_THREAD_COUNT
		}
		qshell.QiniuUpload(int(threadCount), uploadConfigFile)
	} else {
		CmdHelp(cmd)
	}
}
开发者ID:xiqingxl,项目名称:qshell,代码行数:25,代码来源:qupload.go


示例19: main

func main() {
	var err error
	err = database.InitDB(opts.Driver, opts.DataSource)
	if err != nil {
		log.Fatal(err)
	}
	log.Info("gobuild service stated ...")

	http.Handle("/", m)
	http.Handle("/websocket/", websocket.Handler(WsBuildServer))
	http.HandleFunc("/hello", HelloServer)

	if *secure {
		go func() {
			er := http.ListenAndServeTLS(":443", "bin/ssl.crt", "bin/ssl.key", nil)
			if er != nil {
				log.Error(er)
			}
		}()
	}
	err = http.ListenAndServe(opts.ListenAddr, nil)
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:matm,项目名称:gobuild,代码行数:25,代码来源:main.go


示例20: isNeedReload

//是否需要重新下载文件
//判断准则:文件名->文件大小->文件HASH
func (p *Rsf) isNeedReload(item rsf.DumpItem, pos *Pos) bool {
	if item.Time <= p.Config.StartTime {
		return false
	}
	var path string
	if p.Config.EncodeFname == 0 {
		path = p.baseDir + "/data/" + item.Name
	} else {
		key := base64.URLEncoding.EncodeToString([]byte(item.Name))
		h := sha1.New()
		io.WriteString(h, key)
		s := hex.EncodeToString(h.Sum(nil))
		dir := p.baseDir + "/data/" + s[:2] + "/" + s[2:4]
		path = dir + "/" + key
	}
	info, err := os.Stat(path)
	if err != nil || info.Size() != item.Fsize {
		return true
	}
	etag, err := GetEtag(path)
	if err != nil {
		log.Error("GET Etag err:", item)
		return true
	}
	return etag != item.Hash
}
开发者ID:rwifeng,项目名称:qiniutools,代码行数:28,代码来源:main.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang log.Fatal函数代码示例发布时间:2022-05-28
下一篇:
Golang log.Debug函数代码示例发布时间: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