func ExecuteCmd(cmd string, param json.JSONObject, callback function_callback) { call, ok := func_map[cmd] if ok { p := json.NewJSONEmpty() if param.HasMember("aux") || param.HasMember("args") { p = param } else { p.Put("args", param) } id := util.CreateID() is, aux := p.GetJSON("aux") if is && aux.HasMember("id") { } else { aux = json.NewJSONEmpty() p.Put("aux", aux) aux.Put("id", id) } if callback != nil { call_map[id] = callback aux.AddToArray("from", id) aux.Put("action", "callback") } else { aux.Put("action", "direct") } aux.Put("to", cmd) call(p) } }
func CallbackWithFailResult(param json.JSONObject, reason string) { if param != nil { if !param.HasMember("result") { result := json.NewJSONEmpty() param.Put("result", result) } ok, result := param.GetJSON("result") if ok { result.Put("success", false) result.Put("reason", reason) } Callback(param) } }
func CallbackWithSuccessResult(param json.JSONObject, data json.JSONObject) { if param != nil { if !param.HasMember("result") { result := json.NewJSONEmpty() param.Put("result", result) } ok, result := param.GetJSON("result") if ok { result.Put("success", true) if data != nil { result.Put("data", data) } else { result.Put("data", json.NewJSONEmpty()) } } Callback(param) } }