Пример #1
0
func CreateServices(authcfg config.AuthConfig) *AuthServer {

	//初始化db
	logger.Info("Init DB")
	db.Init()

	//初始化cache
	var cacheCfg config.CacheConfig
	if err := config.ReadConfig("etc/maincache.json", &cacheCfg); err != nil {
		logger.Fatal("load config failed, error is: %v", err)
	}
	logger.Info("Init Cache %v", cacheCfg)

	pAuthServices = &AuthServer{
		maincache: db.NewCachePool(cacheCfg),
		rpcServer: rpc.NewServer(),
		exit:      make(chan bool),
	}

	pAuthServices.rpcServer.Register(pAuthServices)

	pAuthServices.rpcServer.ListenAndServe(authcfg.AuthHost, nil)

	return pAuthServices
}
func Register_lua_rpc_RpcServer_newClass(L *lua.LState) int {
	svc := rpc.NewServer()
	svc.SetLuaState(L)
	ud := L.NewUserData()
	ud.Value = svc
	L.SetMetatable(ud, L.GetTypeMetatable(luaRpcServerTypeName))
	L.Push(ud)
	return 1
}
Пример #3
0
func StartServices(self *DBServer, listener net.Listener) {
	rpcServer := rpc.NewServer()
	rpcServer.Register(self)

	for {
		conn, err := listener.Accept()
		if err != nil {
			logger.Error("StartServices %s", err.Error())
			break
		}
		go func() {
			rpcServer.ServeConn(conn)
			conn.Close()
		}()
	}
}