func NewBackendSessionService(ctx *context.Context) *BackendSessionService {

	rpcClient, ok := ctx.GetComponent("corpcclient").(*corpcclient.CoRpcClient)

	if ok == false || rpcClient == nil {
		rpcClient = corpcclient.NewCoRpcClient()
	}

	return &BackendSessionService{rpcClient}
}
Ejemplo n.º 2
0
/// 创建新的CoConnetor组件.
///
/// 创建CoConnector组件时,CoConnector组件使用到的CoSession组件,CoConnection组件一同创建,
/// CoServer组件则通过Context拿到,在CoConnector组件启动时加载.
func NewCoConnector(ctx *context.Context) *CoConnector {

	cocnct, ok := ctx.GetComponent("coconnector").(*CoConnector)
	if ok == true {
		return cocnct
	}

	var decode func([]byte) (interface{}, error)
	var encode func(string, string, map[string]interface{}) ([]byte, error)

	cnct := getConnector(ctx)

	if opts, ok := ctx.AllOpts["coconnector"]; ok == true {
		decode, _ = opts["decode"].(func([]byte) (interface{}, error))
		encode, _ = opts["encode"].(func(string, string, map[string]interface{}) ([]byte, error))
	}

	coserv, ok1 := ctx.GetComponent("coserver").(*coserver.CoServer)
	if ok1 == false {
		coserv = coserver.NewCoServer()
	}

	cosess, ok2 := ctx.GetComponent("cosession").(*cosession.CoSession)
	if ok2 == false {
		cosess = cosession.NewCoSession()
	}

	coconn, ok3 := ctx.GetComponent("coconnection").(*coconnection.CoConnection)
	if ok3 == false {
		coconn = coconnection.NewCoConnection()
	}

	cocnct = &CoConnector{ctx, cnct, coserv, cosess, coconn, decode, encode}
	ctx.RegisteComponent("coconnector", cocnct)
	return cocnct
}