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

Golang retcode.NewStatusOk函数代码示例

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

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



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

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


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

func (self *Store) Op_hash(operation *operations.Hash) (ret bucket.BucketReturn) {

	opGet := operations.Get{
		BucketId: operation.BucketId,
		Key:      operation.Key,
	}
	ret = self.Op_get(&opGet)
	if !ret.GetCode().IsOk() {
		// Error
		return
	}
	if ret.GetCode() == retcode.OkNotFound {
		// Not found, so we cannot hash it
		return
	}

	// Ok, something we can hash
	returnGet := ret.(*operations.GetReturn)
	value := returnGet.Value

	hasher := hasher.NewHasher(value)

	hashreturn := new(operations.HashReturn)
	hashreturn.FirstElementSha256Hash = hasher.FirstElement()
	hashreturn.AllElementsSha256Hash = hasher.AllElements()
	hashreturn.Status = retcode.NewStatusOk()

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


示例4: op_subscribe

func (self *notifierInstance) op_subscribe(operation *operations.Subscribe,
	state *minos.OperationState) (ret bucket.BucketReturn) {

	// Generate the subscription ID and register that ID
	subscriptionId, retStatus := self.putToRegistrationBucket(state, operation)
	if !retStatus.GetCode().IsOk() {
		return &bucket.ReturnGeneric{retStatus.GetStatus()}
	}

	keysForLookupBucket, retStatus := createKeyForLookupBucket(
		operation.MatchChildKeys,
		subscriptionId, operation.Key, state)
	if !retStatus.GetCode().IsOk() {
		return &bucket.ReturnGeneric{retStatus.GetStatus()}
	}

	// Ok, now add to the lookup bucket
	opIterate, retState := self.createPutOperationForLookupBucket(
		keysForLookupBucket, &operation.ReturnConfig)
	if !retState.GetCode().IsOk() {
		return &bucket.ReturnGeneric{retState}
	}
	registerOpRet := state.Dispatcher.Perform(state.Context, opIterate)
	if !registerOpRet.GetCode().IsOk() {
		return &bucket.ReturnGeneric{registerOpRet.GetStatus()}
	}

	return &operations.SubscribeReturn{
		Status: retcode.NewStatusOk(),
		Id:     subscriptionId,
	}
}
开发者ID:cronosun,项目名称:buranv1,代码行数:32,代码来源:op_subscribe.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: 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


示例7: cleanIncubation

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

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

	// Ignore errors (since it's ok to be missing if moved to public)
	_ = os.Remove(filePath)

	key := self.createInformationKey(state, id)

	apiOperation := &operations.Put{
		BucketId: self.bucketId,
		Key:      key,
	}
	opRet := state.Dispatcher.Perform(state.Context, apiOperation)
	if !opRet.GetCode().IsOk() {
		// Unable to remove information
		ret = opRet.GetStatus()
		return
	}
	ret = retcode.NewStatusOk()
	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:26,代码来源:incubator.go


示例8: ReadBucketId

func (self *restContext) ReadBucketId(value *httpserver.Values, key string, optional bool) (
	bucketId bucket.Id,
	bucketIdAsString string,
	status retcode.Status) {

	if optional {
		bucketIdAsString = value.OptionalString(key)
		if bucketIdAsString == "" {
			return
		}
	} else {
		bucketIdAsString, status = value.NonEmptyString(key)
		if !status.IsOk() {
			return
		}
	}

	bucketIdBytes, err := encoding.Base32Decode(bucketIdAsString)
	if err != nil {
		status = retcode.NewStatusFmt(retcode.ErrorClient, "Invalid bucket id given. The id "+
			"has to be base32 without padding. Err: %v", err)
		return
	}
	bucketId = bucket.Id(bucketIdBytes)
	status = retcode.NewStatusOk()
	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:27,代码来源:restcontext.go


示例9: createInstance

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

	ni := new(metadataInstance)
	ni.base = self

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


示例10: unsubscribeSingle

func (self *notifierInstance) unsubscribeSingle(
	subscriptionId operations.SubscriptionId,
	state *minos.OperationState) (status retcode.Status) {

	// Ask the registration bucket
	key := types.Key{[]byte(state.Context.ClientId),
		[]byte(subscriptionId)}
	opGet := operations.Get{
		BucketId: self.registrationsBucketId,
		Key:      key,
	}
	opGetApiRet := state.Dispatcher.Perform(state.Context, &opGet)
	if opGetApiRet.GetCode() == retcode.OkNotFound {
		// No, no such registration
		return opGetApiRet.GetStatus()
	}

	opGetReturn := opGetApiRet.(*operations.GetReturn)
	valueInRegistrationBucketAsKey := opGetReturn.Value.ToKey()
	subscriptionKey := valueInRegistrationBucketAsKey[1:]
	matchChildKeys := deserializeMatchChildKey(valueInRegistrationBucketAsKey[0][0])

	keyInLookupBucket, status := createKeyForLookupBucket(
		matchChildKeys,
		subscriptionId, subscriptionKey, state)
	if !status.Code.IsOk() {
		return
	}

	// Now remove from lookup bucket
	removeOp := operations.Put{
		BucketId: self.keysBucketId,
		Key:      keyInLookupBucket,
		Value:    nil,
	}
	removeOpApiReturn := state.Dispatcher.Perform(state.Context, &removeOp)
	if !removeOpApiReturn.GetCode().IsOk() {
		// Error removing
		status = removeOpApiReturn.GetStatus()
		return
	}

	// Ok, removed, now remove from registration bucket
	removeFromRegistrationBucketOp := operations.Put{
		BucketId: self.registrationsBucketId,
		Key:      key,
		Value:    nil,
	}
	removeFromRegistrationReturn := state.Dispatcher.Perform(state.Context,
		&removeFromRegistrationBucketOp)
	if removeFromRegistrationReturn.GetCode().IsOk() {
		status = retcode.NewStatusOk()
	} else {
		status = removeFromRegistrationReturn.GetStatus()
	}
	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:57,代码来源:op_unsubscribe.go


示例11: NonEmptyString

func (self *Values) NonEmptyString(key string) (value string, status retcode.Status) {
	value = self.valueReader(key)
	if value == "" {
		status = retcode.NewStatusFmt(retcode.ErrorInputFormat, "%v: "+
			"Expecting %v to have a non-empty string - but string is empty.", key)
		return
	}
	status = retcode.NewStatusOk()
	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:10,代码来源:values.go


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


示例13: Globals

func Globals(ctx *caprica.Context) {
	globalsInfoMap := make(map[string]interface{})
	globalsInfoMap[Globals_Key_Blob] =
		ctx.Converter.WriteBucketId(ctx.Caprica.GlobalBlobStoreId())
	globalsInfoMap[Globals_Key_Directory] =
		ctx.Converter.WriteBucketId(ctx.Caprica.GlobalDirectoryId())

	ouput := GlobalsOut{
		Globals: globalsInfoMap,
	}
	ctx.Output.Write(retcode.NewStatusOk(), ouput)
}
开发者ID:cronosun,项目名称:buranv1,代码行数:12,代码来源:globals.go


示例14: incubationFilePath

func (self *incubator) incubationFilePath(state *minos.OperationState,
	id string) (fname string, ret retcode.Status) {

	clientIdAsBase32 := encoding.Base32Encode([]byte(state.Context.ClientId))
	fname, err := state.Files.Filename(self.bucketId, "_"+clientIdAsBase32, id)
	if err != nil {
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}
	ret = retcode.NewStatusOk()
	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:12,代码来源:incubator.go


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


示例16: directoryGet

func directoryGet(ctx *restContext, dirHash []byte, filename string) (
	entry *directoryEntry,
	found bool,
	status retcode.Status) {

	getEntry := &operations.BucketGetIn{
		BucketOperation: operations.BucketOperation{
			BucketId: ctx.caprica.GlobalDirectoryId(),
		},
		Key: [][]byte{dirHash, []byte(filename)},
	}
	var out interface{}
	out, status = ctx.execute(getEntry, operations.BucketGet)

	if !status.IsOk() {
		return
	}
	if status.Code == retcode.OkNotFound {
		return
	}
	found = true

	getEntryReturn := out.(operations.BucketGetOut)
	value := getEntryReturn.Value.([][]byte)

	var targetHash []byte
	err := encoding.Cbor().Decode(value[0], &targetHash)
	if err != nil {
		status = retcode.NewStatusFmt(retcode.ErrorServer, "Unable to decode hash")
		return
	}
	entry = new(directoryEntry)
	entry.targetHash = targetHash
	if len(value) == 1 {
		// Directory
		entry.isDirectory = true
	} else {
		entry.isDirectory = false
		// Mime
		var mime string
		err := encoding.Cbor().Decode(value[1], &mime)
		if err != nil {
			status = retcode.NewStatusFmt(retcode.ErrorServer, "Unable to decode mime")
			return
		}
		entry.mimeType = mime
	}

	status = retcode.NewStatusOk()
	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:51,代码来源:dirget.go


示例17: publicFilePath

func (self *public) publicFilePath(state *minos.OperationState,
	hash []byte) (fname string, ret retcode.Status) {

	hashAsBase32 := encoding.Base32Encode(hash)
	firstBytesAsDirectory := hashAsBase32[:6]
	fname, err := state.Files.Filename(self.bucketId,
		firstBytesAsDirectory, hashAsBase32)
	if err != nil {
		ret = retcode.NewStatusError(retcode.ErrorServer, err)
		return
	}
	ret = retcode.NewStatusOk()
	return
}
开发者ID:cronosun,项目名称:buranv1,代码行数:14,代码来源:public.go


示例18: createPutOperationForLookupBucket

func (self *notifierInstance) createPutOperationForLookupBucket(
	keyForKeysRegistration types.Key,
	returnConfiguration *operations.SubscribeReturnConfig) (
	operation *operations.Put, ret retcode.Status) {

	serializedReturnConfig := serializeConfiguration(returnConfiguration)
	value := types.Array{serializedReturnConfig}

	opPut := operations.Put{
		BucketId: self.keysBucketId,
		Key:      keyForKeysRegistration,
		Value:    value,
	}
	return &opPut, retcode.NewStatusOk()
}
开发者ID:cronosun,项目名称:buranv1,代码行数:15,代码来源:op_subscribe.go


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


示例20: triggerSubscribers

func (self *notifierInstance) triggerSubscribers(operation *operations.Put,
	keysToMatch types.Key,
	matchChildKeys bool,
	state *minos.OperationState) (ret bucket.BucketReturn) {

	numberOfKeyElements := len(keysToMatch)

	matchChildKeysByte := serializeMatchChildKey(matchChildKeys)

	lookupKeyBegin := make(types.Key, numberOfKeyElements+3)
	lookupKeyBegin[0] = []byte{matchChildKeysByte}
	lookupKeyBegin[1] = []byte{byte(numberOfKeyElements)}
	copy(lookupKeyBegin[2:], keysToMatch)
	lookupKeyBegin[len(lookupKeyBegin)-1] = []byte{}

	lookupKeyEnd := make(types.Key, numberOfKeyElements+3)
	lookupKeyEnd[0] = []byte{matchChildKeysByte}
	lookupKeyEnd[1] = []byte{byte(numberOfKeyElements)}
	copy(lookupKeyEnd[2:], keysToMatch)
	lookupKeyEnd[len(lookupKeyEnd)-1] = []byte{255}

	is := new(iterateState)
	is.opPut = operation
	is.notificationReceiver = state.NotificationReceiver
	is.id = state.BucketId

	opIterate := &operations.Iterate{
		BucketId: self.keysBucketId,
		From: operations.Bound{
			Key: lookupKeyBegin,
		},
		To: &operations.Bound{
			Key: lookupKeyEnd,
		},
		Function: is.iterateFunction,
	}
	apiReturn := state.Dispatcher.Perform(state.Context, opIterate)
	if !apiReturn.GetCode().IsOk() {
		return &bucket.ReturnGeneric{apiReturn.GetStatus()}
	}

	if operation.Value != nil {
		return &operations.PutReturn{retcode.NewStatusOk()}
	} else {
		return &operations.PutReturn{retcode.NewStatus(retcode.OkRemove)}
	}
}
开发者ID:cronosun,项目名称:buranv1,代码行数:47,代码来源:op_put.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang btesting.Evaluator类代码示例发布时间:2022-05-23
下一篇:
Golang retcode.NewStatusError函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap