本文整理匯總了Golang中github.com/eaciit/toolkit.NewResult函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewResult函數的具體用法?Golang NewResult怎麽用?Golang NewResult使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewResult函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: KendoGridData
func (c *Controller) KendoGridData(obj orm.IModel, objs interface{}, ins toolkit.M) *toolkit.Result {
result := toolkit.NewResult()
s := c.KendoGridSettings(ins)
//fmt.Printf("Settings: %s \n", toolkit.JsonString(s))
cursor := c.Orm.Find(obj, s)
e = cursor.FetchAll(objs, true)
s.Unset("limit")
s.Unset("skip")
cursor = c.Orm.Find(obj, s)
defer cursor.Close()
count := cursor.Count()
if e != nil {
result.Status = toolkit.Status_NOK
result.Message = e.Error()
} else {
//result.Data = toolkit.M{"Data": dsUsers.Data,
result.Data = toolkit.M{"Data": objs,
"Count": count}
result.Status = toolkit.Status_OK
}
return result
}
示例2: RequestJoin
func (c *Coordinator) RequestJoin(in toolkit.M) *toolkit.Result {
var e error
r := toolkit.NewResult()
referenceID := in.GetString("auth_referenceid")
//toolkit.Println("User ID Request Join : " + referenceID)
secret := in.GetString("auth_secret")
nodeid := in.GetString("nodeid")
noderole := NodeRoleEnum(in.GetString("noderole"))
//--- init node
node := new(Node)
node.ID = nodeid
node.Role = noderole
node.UserID = referenceID
node.Secret = secret
//node.InitRPC()
e = c.AddNode(node)
if e != nil {
r.SetErrorTxt(e.Error())
}
//fmt.Printf("Nodes now:\n%s\n", toolkit.JsonString(c.nodes))
r.Data = node.Secret
return r
}
示例3: Write
/*
Write Write bytes of data into sebar storage.
- Data need to be defined as []byte on in["data"]
- To use memory or disk should be defined on in["storage"] as: MEM, DSK (sebar.StorageTypeMemory, sebar.StorageTypeMemory)
- If no in["storage"] or the value is not eq to either disk or memory, it will be defaulted to memory
*/
func (s *Storage) Write(in toolkit.M) *toolkit.Result {
r := toolkit.NewResult()
key := in.Get("key").(string)
storage := StorageTypeEnum(in.GetString("storage"))
if storage != StorageTypeMemory && storage != StorageTypeDisk {
storage = StorageTypeMemory
}
dataToWrite := in.Get("data").([]byte)
dataLen := len(dataToWrite)
// Validation
nodeCoordinator := s.NodeByID(s.Coordinator)
if nodeCoordinator == nil {
return r.SetErrorTxt(s.Address + " no Coordinator has been setup")
}
// Since all is ok commit the change
var ms *StorageMedia
if storage == StorageTypeMemory {
ms = s.MemoryStorage
} else {
ms = s.DiskStorage
}
ms.write(key, dataToWrite, nodeCoordinator)
s.Log.Info(toolkit.Sprintf("Writing %s (%s) to node %s", key, ParseSize(float64(dataLen)), s.Address))
return r
}
示例4: SubscribeChannel
func (b *Broadcaster) SubscribeChannel(k *knot.WebContext) interface{} {
result := toolkit.NewResult()
var model struct {
Subscriber, Secret, Channel string
}
k.GetPayload(&model)
if b.validateToken("node", model.Secret, model.Subscriber) == false {
result.SetErrorTxt("Subscriber not authorised")
return result
}
model.Channel = strings.ToLower(model.Channel)
subs, exist := b.channelSubscribers[model.Channel]
if !exist {
subs = []string{}
}
for _, s := range subs {
if s == model.Subscriber {
result.SetErrorTxt(fmt.Sprintf("%s has been subscribe to channel %s", model.Subscriber, model.Channel))
return result
}
}
subs = append(subs, model.Subscriber)
b.channelSubscribers[model.Channel] = subs
b.Server.Log().Info(fmt.Sprintf("Node %s successfully subscibed to channel %s. Current subscribers count: %d", model.Subscriber, model.Channel, len(subs)))
return result
}
示例5: CollectMessage
func (s *Subscriber) CollectMessage(k *knot.WebContext) interface{} {
result := toolkit.NewResult()
var model struct {
Secret string
Key string
}
k.GetPayload(&model)
if model.Secret != s.Secret {
result.SetErrorTxt("Call is not authorised")
return result
}
if model.Key == "" {
for k, _ := range s.messages {
model.Key = k
break
}
if model.Key == "" {
result.SetErrorTxt("No key has been provided to collect message")
return result
}
}
var data interface{}
e := s.ReceiveMessage("Que", model.Key, &data)
if e != nil {
result.SetErrorTxt("Unable to get message " + model.Key + " from broadcaster. " + e.Error())
return result
}
result.Data = data
return result
}
示例6: UpdateMetadata
func (c *Coordinator) UpdateMetadata(in toolkit.M) *toolkit.Result {
result := toolkit.NewResult()
keys := []string{}
bs := in.Get("keys", []byte{}).([]byte)
toolkit.FromBytes(bs, "gob", &keys)
return result
}
示例7: Que
func (b *Broadcaster) Que(k *knot.WebContext) interface{} {
result := toolkit.NewResult()
var model struct {
UserID, Secret, Key string
Data interface{}
}
k.GetPayload(&model)
if b.validateToken("user", model.Secret, model.UserID) == false {
result.SetErrorTxt("User " + model.UserID + " is not authorised")
return result
}
targets := b.getChannelSubscribers(model.Key)
if len(targets) == 0 {
result.SetErrorTxt("No subscriber can receive this message")
return result
}
mm := NewMessageMonitor(b, model.Key, model.Data, DefaultExpiry())
mm.DistributionType = DistributeAsQue
result.Data = mm.Message
go func() {
mm.Wait()
}()
return result
}
示例8: RemoveNode
func (b *Broadcaster) RemoveNode(k *knot.WebContext) interface{} {
var nodeModel struct {
Subscriber string
Secret string
}
k.GetPayload(&nodeModel)
result := toolkit.NewResult()
if nodeModel.Subscriber == "" {
result.SetErrorTxt("Invalid subscriber info " + nodeModel.Subscriber)
return result
}
if b.validateToken("node", nodeModel.Secret, nodeModel.Subscriber) == false {
result.SetErrorTxt("Not authorised")
return result
}
sub := b.Subscibers[nodeModel.Subscriber]
_, e := toolkit.CallResult(sub.Url("subscriber/stop"), "POST", toolkit.M{}.Set("secret", sub.Secret).ToBytes("json", nil))
if e != nil {
result.SetErrorTxt(e.Error())
return result
}
delete(b.Subscibers, nodeModel.Subscriber)
k.Server.Log().Info(fmt.Sprintf("%s has been removed as subscriber. Current active subscibers: %d", nodeModel.Subscriber, len(b.Subscibers)))
return result
}
示例9: AddNode
func (b *Broadcaster) AddNode(k *knot.WebContext) interface{} {
var nodeModel struct {
Subscriber string
Secret string
}
k.GetPayload(&nodeModel)
result := toolkit.NewResult()
if nodeModel.Subscriber == "" {
result.SetErrorTxt("Invalid subscriber info " + nodeModel.Subscriber)
return result
}
if nodeModel.Secret != b.secret {
result.SetErrorTxt("Not authorised")
return result
}
if b.Subscibers == nil {
b.Subscibers = map[string]*SubscriberInfo{}
} else {
if _, exist := b.Subscibers[nodeModel.Subscriber]; exist {
result.SetErrorTxt(fmt.Sprintf("%s has been registered as subsriber", nodeModel.Subscriber))
return result
}
}
si := new(SubscriberInfo)
si.Address = nodeModel.Subscriber
si.Protocol = pro
si.Secret = toolkit.RandomString(32)
b.Subscibers[nodeModel.Subscriber] = si
result.Data = si.Secret
k.Server.Log().Info(fmt.Sprintf("%s register as new subscriber. Current active subscibers: %d", nodeModel.Subscriber, len(b.Subscibers)))
return result
}
示例10: StorageStatus
func (s *Storage) StorageStatus(in toolkit.M) *toolkit.Result {
r := toolkit.NewResult()
r.SetBytes(struct {
Memory StorageInfo
Disk StorageInfo
}{s.MemoryStorage.StorageInfo, s.DiskStorage.StorageInfo}, "")
return r
}
示例11: Get
func (c *Coordinator) Get(in toolkit.M) *toolkit.Result {
result := toolkit.NewResult()
result.SetErrorTxt("Get command is still under development")
key := in.GetString("key")
owner, table, datakey := ParseKey(key)
key = MakeKey(owner, table, datakey)
return result
}
示例12: Hi
func (a *controller) Hi(in toolkit.M) *toolkit.Result {
r := toolkit.NewResult()
name := in.GetString("name")
r.SetBytes(struct {
HelloMessage string
TimeNow time.Time
Scores []Score
}{"Hello " + name, time.Now(), []Score{{"Bahasa Indonesia", 90}, {"Math", 85}}}, "gob")
return r
}
示例13: getMsgAsResult
func (s *Subscriber) getMsgAsResult(key string) *toolkit.Result {
result := toolkit.NewResult()
if key == "" {
if len(s.messageKeys) > 0 {
key = s.messageKeys[0]
}
}
// if no key is provided, check from the latest
if key == "" {
result.Status = toolkit.Status_NOK
result.Message = "No key has been provided to receive the message"
} else {
msgQue, exist := s.MessageQues[key]
if !exist {
result.Status = toolkit.Status_NOK
result.Message = "Key " + key + " is not exist on message que or it has been collected. Available keys are: " + strings.Join(s.messageKeys, ",")
} else {
url := fmt.Sprintf("%s/getmsg", s.BroadcasterAddress)
r, e := toolkit.HttpCall(url, "POST",
toolkit.Jsonify(msgQue), nil)
if e != nil {
result.SetErrorTxt("Subscriber ReceiveMsg Call Error: " + e.Error())
} else if r.StatusCode != 200 {
result.SetErrorTxt("Subsciber ReceiveMsg Call Error: " + r.Status)
} else {
//var resultMsg toolkit.Result
e := toolkit.Unjson(toolkit.HttpContent(r),
&result)
if e != nil {
result.SetErrorTxt(fmt.Sprintf("Subsciber ReceiveMsg Decode Error: ", e.Error()))
}
/*else {
if resultMsg.Status == toolkit.Status_OK {
result.Data = resultMsg.Data
} else {
result.SetErrorTxt(resultMsg.Message)
}
}
*/
}
}
}
if result.Status == "OK" {
url := fmt.Sprintf("%s/msgreceived")
toolkit.HttpCall(url, "POST", toolkit.Jsonify(struct {
Key string
Subscriber string
}{key, s.Address}), nil)
}
return result
}
示例14: Logout
func (b *Broadcaster) Logout(k *knot.WebContext) interface{} {
r := toolkit.NewResult()
m := toolkit.M{}
k.GetPayload(&m)
if !b.validateToken("user", m.GetString("secret"), m.GetString("userid")) {
r.SetErrorTxt("Not authorised")
return r
}
delete(b.userTokens, m.GetString("userid"))
return r
}
示例15: Call
func (a *Client) Call(methodName string, in toolkit.M) *toolkit.Result {
if a.client == nil {
return toolkit.NewResult().SetErrorTxt("Unable to call, no connection handshake")
}
if in == nil {
in = toolkit.M{}
}
out := toolkit.NewResult()
in["method"] = methodName
if in.GetString("auth_referenceid") == "" {
in["auth_referenceid"] = a.sessionID
}
//fmt.Println("SessionID: " + a.sessionID)
if in.Has("auth_secret") == false {
in.Set("auth_secret", a.secret)
}
e := a.client.Call("Rpc.Do", in, out)
//_ = "breakpoint"
if e != nil {
return out.SetErrorTxt(a.address + "." + methodName + " Fail: " + e.Error())
}
return out
}