func (r *Router) toNodeAction(msg *message.Message) (reply *message.Reply) { switch msg.Action { case message.ADD: body := msg.UnmarshalToAddNode() r.net.AddNode(engine.NewObjectId(body.Id)) case message.DEL: r.msgs.Put(msg.Target, msg) reply.Value = nil reply.State = 200 return nil case message.PUT: r.msgs.Put(msg.Target, msg) reply.Value = nil reply.State = 200 return nil case message.GET: r.msgs.Put(msg.Target, msg) reply.Value = nil reply.State = 200 return nil default: v, _ := json.Marshal(errors.New("action type is null")) reply = &message.Reply{ Value: v, State: 201, } return } reply = &message.Reply{ Value: nil, State: 200, } return reply }
func (r *Router) toNodeAction(msg *message.Message, reply *message.Reply) (err error) { switch msg.Action { case message.ADD: body := msg.UnmarshalToAddNode() // println(body.Id) n := r.net.AddNode(engine.NewObjectId(body.Id)) if n != nil { reply.Value, _ = json.Marshal(n.Index.ToByte()) reply.State = 200 return nil } else { reply.Value = nil reply.State = 201 return errors.New("text") } case message.DEL: r.msgs.Put(msg.Target, msg) reply.Value = nil reply.State = 200 return nil case message.PUT: r.msgs.Put(msg.Target, msg) reply.Value = nil reply.State = 200 return nil case message.GET: r.msgs.Put(msg.Target, msg) reply.Value = nil reply.State = 200 return nil default: v, _ := json.Marshal(errors.New("action type is null")) reply = &message.Reply{ Value: v, State: 201, } return } return errors.New("unknown errors.") }