本文整理汇总了Golang中github.com/cronosun/buranv1/ares/retcode.NewStatusOk函数的典型用法代码示例。如果您正苦于以下问题:Golang NewStatusOk函数的具体用法?Golang NewStatusOk怎么用?Golang NewStatusOk使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewStatusOk函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
}
示例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()
}
示例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
}
示例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,
}
}
示例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()
}
示例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
}
示例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
}
示例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
}
示例9: createInstance
func (self *metadataStruct) createInstance(state *minos.OperationState) (
instance *metadataInstance,
ret retcode.Status) {
ni := new(metadataInstance)
ni.base = self
return ni, retcode.NewStatusOk()
}
示例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
}
示例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
}
示例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,
}
}
示例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)
}
示例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
}
示例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()}
}