Exemple #1
0
func (this *fdfsClient) downloadToBufferByOffset(fileId string, offset int64, downloadSize int64, catInstance cat.Cat) ([]byte, error) {
	//split file id to two parts: group name and file name
	tmp, err := splitRemoteFileId(fileId)
	if err != nil || len(tmp) != 2 {
		return nil, err
	}
	groupName := tmp[0]
	fileName := tmp[1]

	//query a download server from tracker
	storeInfo, err := this.tracker.trackerQueryStorageFetch(groupName, fileName)
	if err != nil {
		return nil, err
	}
	if catInstance != nil {
		event := catInstance.NewEvent("ImgFromStorage", fmt.Sprintf("%s:%s", storeInfo.groupName, storeInfo.ipAddr))
		event.SetStatus("0")
		event.Complete()
	}

	//get a storage client from storage map, if not exist, create a new storage client
	storeClient, err := this.getStorage(storeInfo.ipAddr, storeInfo.port)
	if err != nil {
		return nil, err
	}
	return storeClient.storageDownload(storeInfo, offset, downloadSize, fileName)
}
Exemple #2
0
func EncodeRequest(Cat cat.Cat, bts []byte, req *request.Request) util.Error {
	soapTran := Cat.NewTransaction("SOAP", "EncodeRequest")
	result := util.Error{}
	defer func() {
		if result.Err != nil && !result.IsNormal {
			soapTran.SetStatus(result.Err)
		} else {
			soapTran.SetStatus(CATTRANSUCCESS)
		}
		soapTran.Complete()
	}()
	if err := soapparse.EncReq(bts, req); err != nil {
		util.LogErrorEvent(Cat, "SoapParseRequestError", err.Error())
		result = util.Error{IsNormal: false, Err: err, Type: "SoapParseRequestError"}
	}
	return result
}
Exemple #3
0
func DecodeResponse(Cat cat.Cat, header *response.Header, resp interface{}) ([]byte, util.Error) {
	soapTran := Cat.NewTransaction("SOAP", "DecodeResponse")
	result := util.Error{}
	defer func() {
		if result.Err != nil && !result.IsNormal {
			soapTran.SetStatus(result.Err)
		} else {
			soapTran.SetStatus(CATTRANSUCCESS)
		}
		soapTran.Complete()
	}()
	content, err := soapparse.DecResp(header, resp) //
	if err != nil {
		util.LogErrorEvent(Cat, "SoapParseResponseError", err.Error())
		result = util.Error{IsNormal: false, Err: err, Type: "SoapParseResponseError"}
	}
	return content, result
}
Exemple #4
0
func postHandle(c cat.Cat, tran cat.Transaction, imagePath string, w http.ResponseWriter, err *error, handleOk *bool) {
	p := recover()
	if p != nil {
		c.LogPanic(p)
		tran.SetStatus(p)
		log.WithFields(log.Fields{"uri": imagePath}).Error(*err)
	}

	if *handleOk {
		tran.SetStatus("0")
		tran.Complete()
	} else {
		tran.SetStatus(*err)
		tran.Complete()
	}
	if p != nil || *err != nil {
		http.Error(w, http.StatusText(404), 404)
	}
}
func logEvent(cat cat.Cat, title string, name string, data map[string]string) {
	event := cat.NewEvent(title, name)
	if data != nil {
		for k, v := range data {
			event.AddData(k, v)
		}
	}
	event.SetStatus("0")
	event.Complete()
}