当前位置: 首页>>代码示例>>Golang>>正文


Golang retcode.NewStatusError函数代码示例

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


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

示例1: Perform

func (self *dispatcherimpl) Perform(context *ares.Context,
	operation ares.Operation) (ret ares.Return) {
	if context == nil {
		context = new(ares.Context)
	}

	if context.Level > contextLevelMaximum {
		return &operations.GenericReturn{retcode.NewStatusError(retcode.ErrorClient,
			errors.New(fmt.Sprintf("Maximum level is %v - reconfigure buckets",
				contextLevelMaximum)))}
	}

	switch operation := operation.(type) {
	case *operations.Forwarded:
		// Is forwarded
		return self.perform_BucketOperation(context, operation.Original, operation.BucketId)
	case operations.HasTargetBucketId:
		// If it has a target bucket id, send it to that bucket.
		return self.perform_BucketOperation(context, operation, operation.TargetBucketId())
	case *operations.CreateBucket:
		return self.perform_OpCreateBucket(context, operation)
	default:
		return &operations.GenericReturn{retcode.NewStatusError(retcode.ErrorClient,
			errors.New(fmt.Sprintf("Unknown operation: %T, %v", operation, operation)))}
	}
}
开发者ID:cronosun,项目名称:buranv1,代码行数:26,代码来源:api_impl.go

示例2: createInstance

func (self *notifier) createInstance(state *minos.OperationState) (
	instance *notifierInstance,
	ret retcode.Status) {

	var err error
	keysBucketId, exists, err := state.MetadataGetterSetter.Forwarder(
		true, metadataKey_keys)
	if err != nil || !exists {
		return nil, retcode.NewStatusError(
			retcode.ErrorServer, errors.New("Could not get forwarder metadata (keys)"))
	}
	registrationsBucketId, exists, err := state.MetadataGetterSetter.Forwarder(
		true, metadataKey_registrations)
	if err != nil || !exists {
		return nil, retcode.NewStatusError(
			retcode.ErrorServer, errors.New("Could not get forwarder metadata (keys)"))
	}

	ni := new(notifierInstance)
	ni.base = self
	ni.keysBucketId = keysBucketId
	ni.registrationsBucketId = registrationsBucketId

	return ni, retcode.NewStatusOk()
}
开发者ID:cronosun,项目名称:buranv1,代码行数:25,代码来源:notifier.go

示例3: createInstance

func (self *blobstorePrototype) createInstance(state *minos.OperationState) (
	instance *blobstoreStruct,
	ret retcode.Status) {

	var err error
	backendId, exists, err := state.MetadataGetterSetter.Forwarder(
		true, metadataKey_backend)
	if err != nil {
		return nil, retcode.NewStatusError(
			retcode.ErrorServer, errors.New("Could not get forwarder metadata (backend)"))
	}
	if !exists {
		return nil, retcode.NewStatusError(
			retcode.ErrorServer, errors.New("Backend bucket id not found in metadata"))
	}

	ni := new(blobstoreStruct)
	ni.incubator = new(incubator)
	ni.incubator.bucketId = backendId
	ni.public = new(public)
	ni.public.bucketId = backendId
	ni.public.incubator = ni.incubator

	return ni, retcode.NewStatusOk()
}
开发者ID:cronosun,项目名称:buranv1,代码行数:25,代码来源:blobstore.go

示例4: Op_put

func (self *Store) Op_put(operation *operations.Put) (ret bucket.BucketReturn) {
	leveldb, err := self.Database()
	if err != nil {
		return &bucket.ReturnGeneric{retcode.NewStatusError(retcode.ErrorServer, err)}
	}

	keyBytes := self.KeyToBytesAndPrefix(operation.Key)

	// Success, now forward that thing (forwarding never fails)
	if self.State.PutForwarder != nil && !self.DoNotPutForward {
		self.State.PutForwarder.ForwardIfOk(operation)
	}

	var returnValue *operations.PutReturn
	if operation.Value != nil {
		valueBytes := operation.Value.Serialize()
		//fmt.Printf("PUT: %v\n", keyBytes)

		err = leveldb.Put(keyBytes, valueBytes, nil /*TODO*/)
		if err != nil {
			return &bucket.ReturnGeneric{retcode.NewStatusError(retcode.ErrorServer, err)}
		}
		returnValue = &operations.PutReturn{retcode.NewStatusOk()}
	} else {
		// Remove operation
		err = leveldb.Delete(keyBytes, nil)
		if err != nil {
			return &bucket.ReturnGeneric{retcode.NewStatusError(retcode.ErrorServer, err)}
		}
		returnValue = &operations.PutReturn{retcode.NewStatus(retcode.OkRemove)}
	}

	return returnValue
}
开发者ID:cronosun,项目名称:buranv1,代码行数:34,代码来源:op_put.go

示例5: createInstance

func (self *directoryBucket) createInstance(state *minos.OperationState) (
	instance *directoryBucketInstance,
	ret retcode.Status) {

	var err error
	backendId, exists, err := state.MetadataGetterSetter.Forwarder(
		true, forwarder_name)
	if err != nil {
		return nil, retcode.NewStatusError(
			retcode.ErrorServer, errors.New("Could not get forwarder metadata (backend)"))
	}
	if !exists {
		return nil, retcode.NewStatusError(
			retcode.ErrorServer, errors.New("Backend bucket id not found in metadata"))
	}

	cstore := &commonstore.Store{
		DbTypeName:       levelDbTypeName,
		DatabaseProvider: self.database,
		State:            state,
		DoNotPutForward:  true,
	}

	ni := new(directoryBucketInstance)
	ni.base = self
	ni.cstore = cstore
	ni.backendId = backendId

	return ni, retcode.NewStatusOk()
}
开发者ID:cronosun,项目名称:buranv1,代码行数:30,代码来源:directory.go

示例6: perform_BucketOperation

func (self *dispatcherimpl) perform_BucketOperation(context *ares.Context,
	operation ares.Operation,
	targetBucketId bucket.Id) (
	ret ares.Return) {

	bucketId := targetBucketId

	if bucketId == nil || len(bucketId) == 0 {
		return &operations.GenericReturn{retcode.NewStatusError(retcode.ErrorClient,
			errors.New("Bucket ID is missing or invalid"))}
	}

	bucketType := self.typesRegistry.BucketType(bucketId.TypeId())
	if bucketType == nil {
		return &operations.GenericReturn{retcode.NewStatusError(retcode.ErrorClient,
			errors.New(fmt.Sprintf("BucketType %v not found", bucketId.TypeId())))}
	}

	var err error

	// Special case for metadata
	if bucketId.IsMetadata() {
		// Extract and supply the original bucket ID to the metadata
		bucketId = bucketId.ExtractOriginalId()
	}

	metadataReader, err := self.metadata.TypedGetterSetter(bucketId)
	if err != nil {
		return &operations.GenericReturn{
			retcode.NewStatusError(retcode.ErrorBucketIdNotFound, err)}
	}

	state := new(minos.OperationState)
	state.Operation = operation
	state.BucketId = bucketId

	putfowarderVar := new(putfowarder)
	putfowarderVar.metadataReader = metadataReader
	putfowarderVar.putReceiversIds, err = metadataReader.PutReceivers()
	putfowarderVar.context = *context
	putfowarderVar.forwardFunction = self.Perform

	state.PutForwarder = putfowarderVar
	state.MetadataGetterSetter = metadataReader
	state.NotificationReceiver = self.receiveNotification
	state.Context = context
	state.Dispatcher = self
	state.Locker = self.lock
	state.Files = self.files
	state.BucketType = self.typesRegistry.BucketType

	bucketReturn := bucketType.Perform(state)
	putfowarderVar.maybeDoPutForward(bucketReturn)
	return bucketReturn
}
开发者ID:cronosun,项目名称:buranv1,代码行数:55,代码来源:op_bucket.go

示例7: Op_iterate

func (self *Store) Op_iterate(operation *operations.Iterate) (
	ret bucket.BucketReturn) {

	database, err := self.Database()
	if err != nil {
		ret = &bucket.ReturnGeneric{retcode.NewStatusError(retcode.ErrorServer, err)}
		return
	}

	r, err := self.createScanRangeForIterate(operation, self.State.BucketId)
	if err != nil {
		ret = &bucket.ReturnGeneric{retcode.NewStatusError(retcode.ErrorClient, err)}
		return
	}
	iterator := database.NewIterator(r, nil)
	defer iterator.Release()

	var exhausted bool
	exhausted = !iterator.First()
	resultNumber := 0
	var numberOfErrors uint32
	numberOfErrors = 0
	for !exhausted {
		key, err := typescommon.PrefixedKeyBytesToKey(
			self.State.BucketId, iterator.Key())
		if err != nil {
			numberOfErrors++
		} else {
			value, err := types.NewArrayFromBytes(iterator.Value())
			if err != nil {
				numberOfErrors++
			} else {
				// Ok
				iterateState := new(operations.IterateState)
				iterateState.ResultNumber = uint32(resultNumber)
				iterateState.Key = key
				iterateState.Value = value

				end := operation.Function(iterateState)
				if end {
					break
				}
			}
		}
		resultNumber++
		exhausted = iterator.Next()
		exhausted = !iterator.Valid() //TODO: Why do we need this too?
	}

	return &operations.IterateReturn{
		Status:         retcode.NewStatusOk(),
		NumberOfErrors: numberOfErrors,
	}
}
开发者ID:cronosun,项目名称:buranv1,代码行数:54,代码来源:op_iterate.go

示例8: perform_OpCreateBucket

func (self *dispatcherimpl) perform_OpCreateBucket(context *ares.Context,
	operation *operations.CreateBucket) (
	ret ares.Return) {

	if context.UserId.IsPublicUser() {
		return &operations.GenericReturn{retcode.NewStatusError(
			retcode.ErrorNotAllowedForPublicUser,
			errors.New("Need to be authenticated"))}
	}

	/* Validate and create */
	bucketType := self.typesRegistry.BucketType(operation.TypeId)
	if bucketType == nil {
		return &operations.GenericReturn{retcode.NewStatusError(retcode.ErrorClient,
			errors.New(fmt.Sprintf("BucketType %v not found", operation.TypeId)))}
	}
	if operation.TypeId.IsMetadata() {
		return &operations.GenericReturn{retcode.NewStatusError(retcode.ErrorClient,
			errors.New("You tried to create a metadata bucket (bucket type). That's "+
				"not possible, since metadata buckets are only 'virtual' and cannot "+
				"be created (convert a bucket ID to a metadata bucket ID to access its "+
				"metadata)."))}
	}

	createdMetadata := operation.Metadata
	if createdMetadata == nil {
		createdMetadata = make(map[string]([]byte))
	}

	createState := new(minos.CreateState)
	createState.TypeId = operation.TypeId
	createState.Metadata = self.metadata.NewMemoryTypedReaderWriter(createdMetadata)
	createState.Context = context
	createState.Dispatcher = self
	createState.Files = self.files

	status := bucketType.Create(createState)
	if !status.GetCode().IsOk() {
		return &operations.GenericReturn{status}
	}

	/* Now create the bucket */
	bucketId, err := self.metadata.Create(operation.TypeId, createdMetadata,
		context.UserId)
	if err != nil {
		// TODO: Rollback what 'bucketType.Create' did
		return &operations.GenericReturn{retcode.NewStatusError(retcode.ErrorServer, err)}
	}

	// Done
	return &operations.CreateBucketReturn{bucketId, retcode.NewStatusOk()}
}
开发者ID:cronosun,项目名称:buranv1,代码行数:52,代码来源:op_createBucket.go

示例9: appendDataWithoutCleanup

func (self *incubator) appendDataWithoutCleanup(state *minos.OperationState,
	id string, data []byte) (ret retcode.Status) {

	// Make sure it exists (but do not remove existing)
	self.new(state, id, false)

	currentIncubationState, ret := self.information(state, id)
	if !ret.IsOk() {
		return
	}

	// Initialize the hash how we left it the last time
	hash := currentIncubationState.restoreHash()

	// Update the hash
	_, err := hash.Write(data)
	if err != nil {
		err = errors.New(fmt.Sprintf("Unable to write to hash: %v", err))
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}

	// Update the file
	filePath, ret := self.incubationFilePath(state, id)
	if !ret.IsOk() {
		return
	}
	file, err := os.OpenFile(filePath, os.O_RDWR|os.O_APPEND, 0660)
	if err != nil {
		err = errors.New(fmt.Sprintf("Unable to open incubation file: %v", err))
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}
	defer file.Close()
	_, err = file.Write(data)
	if err != nil {
		err = errors.New(fmt.Sprintf("Unable write to incubation file: %v", err))
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}

	// Ok, now update the information
	currentIncubationState.length += uint64(len(data))
	currentIncubationState.hashState = hash.Serialize()
	ret = self.writeInformation(state, id, &currentIncubationState)

	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:48,代码来源:incubator.go

示例10: new

func (self *incubator) new(state *minos.OperationState,
	id string,
	removeIfAlreadyExisting bool) (ret retcode.Status) {

	// See if it already exists (and maybe remove it)
	_, ret = self.information(state, id)
	if !ret.IsOk() {
		return
	}
	alreadyFound := ret.Code != retcode.OkNotFound
	if alreadyFound && removeIfAlreadyExisting {
		// Ok, remove current
		ret = self.cleanIncubation(state, id)
		if !ret.IsOk() {
			return
		}
	}

	if !alreadyFound {
		// Create it
		hash := serializablehash.NewSha256()
		newState := new(incubationState)
		newState.length = 0
		newState.hashState = hash.Serialize()
		self.writeInformation(state, id, newState)

		// Create empty file
		filePath, retLocal := self.incubationFilePath(state, id)
		if !retLocal.IsOk() {
			ret = retLocal
			return
		}
		file, err := os.Create(filePath)
		if err != nil {
			err = errors.New(fmt.Sprintf("Unable to create incubation file: %v", err))
			ret = retcode.NewStatusError(retcode.ErrorServer, err)
			return
		}
		err = file.Close()
		if err != nil {
			err = errors.New(fmt.Sprintf("To close incubation file: %v", err))
			ret = retcode.NewStatusError(retcode.ErrorServer, err)
			return
		}
	}
	ret = retcode.NewStatusOk()
	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:48,代码来源:incubator.go

示例11: information

func (self *incubator) information(state *minos.OperationState,
	id string) (incState incubationState, ret retcode.Status) {

	key := self.createInformationKey(state, id)

	apiOperation := &operations.Get{
		BucketId: self.bucketId,
		Key:      key,
	}
	opRet := state.Dispatcher.Perform(state.Context, apiOperation)
	if opRet.GetCode() != retcode.Ok {
		// Not found or a different error
		ret = opRet.GetStatus()
		return
	}

	// Ok, found it, deserialize
	retCast := opRet.(*operations.GetReturn)
	value := retCast.Value

	incState = incubationState{}
	incState.hashState = value[0]
	err := encoding.Cbor().Decode(value[1], &incState.length)
	if err != nil {
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}

	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:30,代码来源:incubator.go

示例12: information

func (self *public) information(state *minos.OperationState,
	hash []byte) (pubState publicState, ret retcode.Status) {

	key := self.clreatePublicKey(state, hash)

	apiOperation := &operations.Get{
		BucketId: self.bucketId,
		Key:      key,
	}
	opRet := state.Dispatcher.Perform(state.Context, apiOperation)
	if opRet.GetCode() != retcode.Ok {
		// Not found or a different error
		ret = opRet.GetStatus()
		return
	}

	// Ok, found it, deserialize
	retCast := opRet.(*operations.GetReturn)
	value := retCast.Value

	pubState = publicState{}
	pubState.data = value[0]
	err := encoding.Cbor().Decode(value[1], &pubState.length)
	if err != nil {
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}

	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:30,代码来源:public.go

示例13: writeInformation

func (self *incubator) writeInformation(state *minos.OperationState,
	id string, incState *incubationState) (ret retcode.Status) {

	key := self.createInformationKey(state, id)

	encodedLength, err := encoding.Cbor().Encode(incState.length)
	if err != nil {
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}
	value := types.Array{incState.hashState, encodedLength}

	apiOperation := &operations.Put{
		BucketId: self.bucketId,
		Key:      key,
		Value:    value,
	}
	opRet := state.Dispatcher.Perform(state.Context, apiOperation)
	if !opRet.GetCode().IsOk() {
		// Unable to put
		ret = opRet.GetStatus()
		return
	}

	return opRet.GetStatus()
}
开发者ID:cronosun,项目名称:buranv1,代码行数:26,代码来源:incubator.go

示例14: Perform

func (self *directoryBucket) Perform(state *minos.OperationState) (
	bucketReturn ares.Return) {

	operation := state.Operation
	instance, ret := self.createInstance(state)
	if !ret.IsOk() {
		return &bucket.ReturnGeneric{ret.GetStatus()}
	}

	switch operation := operation.(type) {
	case *operations.Put:
		// Handle internally
		return instance.opPut(operation, state)
	case *operations.Exists:
		// Forward to backing store
		return instance.cstore.Perform(state)
	case *operations.Get:
		// Forward to backing store
		return instance.cstore.Perform(state)
	case *operations.Hash:
		// Forward to backing store
		return instance.cstore.Perform(state)
	case *operations.Scan:
		// Scan is supported but has some limits
		return instance.opScan(operation, state)
	default:
		return &bucket.ReturnGeneric{retcode.NewStatusError(
			retcode.ErrorOperationNotSupported, errors.New(fmt.Sprintf(
				"Bucket operation not supported (directory): %v\n", reflect.TypeOf(operation))))}
	}
}
开发者ID:cronosun,项目名称:buranv1,代码行数:31,代码来源:directory.go

示例15: writeInformation

func (self *public) writeInformation(state *minos.OperationState,
	hash []byte, pubState *publicState) (ret retcode.Status) {

	key := self.clreatePublicKey(state, hash)

	encodedLength, err := encoding.Cbor().Encode(pubState.length)
	if err != nil {
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}
	if pubState.data == nil {
		pubState.data = []byte{}
	}
	value := types.Array{pubState.data, encodedLength}
	apiOperation := &operations.Put{
		BucketId: self.bucketId,
		Key:      key,
		Value:    value,
	}
	opRet := state.Dispatcher.Perform(state.Context, apiOperation)
	if !opRet.GetCode().IsOk() {
		// Unable to put
		ret = opRet.GetStatus()
		return
	}

	return opRet.GetStatus()
}
开发者ID:cronosun,项目名称:buranv1,代码行数:28,代码来源:public.go


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