예제 #1
0
파일: storage.go 프로젝트: chenbk85/nephele
func (this *NfsStorage) Download() ([]byte, util.Error) {
	var (
		bts []byte
		err error
	)
	var messagesize int
	if this.Cat != nil {
		tran := this.Cat.NewTransaction(CATTITLE, "Nfs.Download")
		tran.AddData("path", this.Path)
		defer func() {
			if err != nil {
				tran.SetStatus(err)
			} else {
				util.LogEvent(this.Cat, "Size", util.GetImageSizeDistribution(messagesize), map[string]string{"size": strconv.Itoa(messagesize)})
				tran.SetStatus("0")
			}
			tran.Complete()
		}()
	}
	bts, err = ioutil.ReadFile(this.Path)
	if err != nil {
		util.LogErrorEvent(this.Cat, ERRORTYPE_NFSDOWNLOADERR, err.Error())
		return []byte{}, util.Error{IsNormal: false, Err: err, Type: ERRORTYPE_NFSDOWNLOADERR}
	}
	messagesize = len(bts)
	return bts, util.Error{}
}
예제 #2
0
파일: storage.go 프로젝트: chenbk85/nephele
func (this *FdfsStorage) Download() ([]byte, util.Error) {
	if e := this.initFdfsClient(); e.Err != nil {
		return nil, e
	}
	var (
		bts    []byte
		err    error
		result = util.Error{}
	)
	var messagesize int
	if this.Cat != nil {
		tran := this.Cat.NewTransaction(CATTITLE, "Fdfs.Download")
		tran.AddData("path", this.Path)
		defer func() {
			if result.Err != nil && result.IsNormal {
				tran.SetStatus(result.Err)
			} else {
				util.LogEvent(this.Cat, "Size", util.GetImageSizeDistribution(messagesize), map[string]string{"size": strconv.Itoa(messagesize)})
				tran.SetStatus("0")
			}
			tran.Complete()
		}()
	}
	bts, err = fdfsClient.DownloadToBuffer(this.Path, this.Cat)
	if err != nil {
		util.LogErrorEvent(this.Cat, ERRORTYPE_FDFSDOWNLOADERR, err.Error())
		result = util.Error{IsNormal: false, Err: err, Type: ERRORTYPE_FDFSDOWNLOADERR}
		return []byte{}, result
	}
	messagesize = len(bts)
	return bts, result
}
예제 #3
0
파일: storage.go 프로젝트: chenbk85/nephele
func (this *FdfsStorage) Upload(bts []byte, fileExt string) (string, util.Error) {
	if e := this.initFdfsClient(); e.Err != nil {
		return "", e
	}
	config := models.Config{Cat: this.Cat}
	groups, e := config.GetGroups()
	if e.Err != nil {
		return "", e
	}
	if uploadcount == 99999999 {
		uploadcount = 0
	}
	i := uploadcount % len(groups)
	uploadcount = 0
	g := groups[i]

	var result util.Error = util.Error{}
	if this.Cat != nil {
		tran := this.Cat.NewTransaction(CATTITLE, "Fdfs.Upload")
		util.LogEvent(this.Cat, "Size", util.GetImageSizeDistribution(len(bts)), map[string]string{"size": strconv.Itoa(len(bts))})

		defer func() {
			if result.Err != nil && result.IsNormal {
				tran.SetStatus(result.Err)
			} else {
				tran.SetStatus("0")
			}
			tran.Complete()
		}()
	}
	path, err := fdfsClient.UploadByBuffer(g, bts, fileExt)
	if err != nil {
		util.LogErrorEvent(this.Cat, ERRORTYPE_FDFSUPLOADERR, err.Error())
		result = util.Error{IsNormal: false, Err: err, Type: ERRORTYPE_FDFSUPLOADERR}
		return "", result
	}
	return path, result
}