Exemple #1
0
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 ParseAuthServerConfig(jsonObject json.JSONObject) *AuthServerConfig {
	a := new(AuthServerConfig)
	port_ok, port := jsonObject.GetInt("port")
	if port_ok {
		a.Port = port
	}
	return a
}
func PaserRouteServerConfig(jsonObject json.JSONObject) *RouteServerConfig {
	r := new(RouteServerConfig)

	port_ok, port := jsonObject.GetInt("port")
	if port_ok {
		r.Port = port
	}

	return r
}
Exemple #4
0
func Callback(param json.JSONObject) {
	if param != nil {
		is, aux := param.GetJSON("aux")
		if is {
			iss, arr := aux.GetArray("from")
			if iss {
				last, isss := arr.GetLast().(string)
				if isss {
					call_map[last](param)
					aux.RemoveLast("from")
				}
			}
		}
	}
}
Exemple #5
0
func ExecuteCmd1(param json.JSONObject, callback function_callback) {
	if param != nil {
		aux_ok, aux := param.GetJSON("aux")
		if aux_ok {
			name_ok, name := aux.GetString("to")
			if name_ok {
				ExecuteCmd(name, param, callback)
			} else {
				log.E_COM("execute cmd error, reason : aux has not name paramter")
			}
		} else {
			log.E_COM("execute cmd error, reason : param has not aux paramter")
		}
	} else {
		log.E_COM("execute cmd error, reason : param is nil")
	}
}
Exemple #6
0
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 ParseConnectionServerConfig(jsonObject json.JSONObject) (bool, *ConnectionServerConfig) {
	config := new(ConnectionServerConfig)

	port_ok, port := jsonObject.GetInt("port")
	if port_ok {
		config.Port = port
	}
	route_ok, route := jsonObject.GetString("route_address")
	if route_ok {
		config.RouteAddress = route
	}
	auth_ok, auth := jsonObject.GetString("auth_address")
	if auth_ok {
		config.AuthAddress = auth
	}

	return true, config
}
Exemple #8
0
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)
	}
}