Exemple #1
0
func main() {
	cfg := kolonsecfg.NewCfg()
	cfg.ParseFile(*cfgPath)
	cfgNode := cfg.Child(*env)
	logger := logs.NewLogger(10000)
	// 创建配置日志文件目录
	os.MkdirAll(cfgNode.Child("log.logdir").GetString(), 0777)
	filename := path.Join(cfgNode.Child("log.logdir").GetString(),
		cfgNode.Child("log.filename").GetString())
	logCfg := map[string]interface{}{
		"filename": filename,
		"maxlines": cfgNode.Child("log.maxlines").GetInt(),
		"maxsize":  cfgNode.Child("log.maxsize").GetInt(),
		"daily":    cfgNode.Child("log.daily").GetBool(),
		"maxdays":  cfgNode.Child("log.maxdays").GetInt(),
		"rotate":   cfgNode.Child("log.rotate").GetBool(),
	}
	buff, _ := json.Marshal(logCfg)
	err := logger.SetLogger("file", string(buff))
	if err != nil {
		panic(err.Error())
	}
	err = logger.SetLogger("console", "")
	if err != nil {
		panic(err.Error())
	}
	logger.Info("当前环境:%v 加载配置:\n%v", *env, cfgNode.Dump(""))
	ts := TCPServer.NewTCPServer(cfgNode.Child("serveraddr").GetString())
	ts.Register("logger", logger)
	ts.Register("newConnCB", function.Bind(ClientConnect, function.P_1))
	ts.Register("recvCB", function.Bind(ClientDataRecv, function.P_1, function.P_2, function.P_3))
	ts.Server()
}
Exemple #2
0
func (si *ServerInfo) Start(port int) error {
	channelHost := ":" + strconv.Itoa(port+1)
	serverHost := ":" + strconv.Itoa(port)
	si.Channel = t.NewTCPServer(channelHost)
	si.Server = t.NewTCPServer(serverHost)

	si.Channel.Register("newConnCB", function.Bind(si.channelConn, function.P_1))
	si.Channel.Register("recvCB", function.Bind(si.channelRecv,
		function.P_1,
		function.P_2,
		function.P_3))

	si.Server.Register("newConnCB", function.Bind(si.serverConn, function.P_1))
	si.Server.Register("recvCB", function.Bind(si.serverRecv,
		function.P_1,
		function.P_2,
		function.P_3))
	err := si.Channel.Server()
	if err == nil {
		err = si.Server.Server()
	}
	return err
}