Exemplo n.º 1
0
func init() {
	var err error

	// 读取配置文件内容
	config, err := configUtil.ReadJsonConfig(CONFIG_FILE_NAME)
	checkError(err)

	// 解析ServerGroupId
	ServerGroupId, err = configUtil.ReadIntJsonValue(config, "ServerGroupId")
	checkError(err)

	// 解析ChatDBConnection配置
	ChatDBConnection, err = configUtil.ReadStringJsonValue(config, "ChatDBConnection")
	checkError(err)
	ChatDBMaxOpenConns, err = configUtil.ReadIntJsonValue(config, "ChatDBMaxOpenConns")
	checkError(err)
	ChatDBMaxIdleConns, err = configUtil.ReadIntJsonValue(config, "ChatDBMaxIdleConns")
	checkError(err)

	// 解析ModelDBConnection配置
	ModelDBConnection, err = configUtil.ReadStringJsonValue(config, "ModelDBConnection")
	checkError(err)
	ModelDBMaxOpenConns, err = configUtil.ReadIntJsonValue(config, "ModelDBMaxOpenConns")
	checkError(err)
	ModelDBMaxIdleConns, err = configUtil.ReadIntJsonValue(config, "ModelDBMaxIdleConns")
	checkError(err)

	// 解析GameDBConnection配置
	GameDBConnection, err = configUtil.ReadStringJsonValue(config, "GameDBConnection")
	checkError(err)
	GameDBMaxOpenConns, err = configUtil.ReadIntJsonValue(config, "GameDBMaxOpenConns")
	checkError(err)
	GameDBMaxIdleConns, err = configUtil.ReadIntJsonValue(config, "GameDBMaxIdleConns")
	checkError(err)
}
Exemplo n.º 2
0
func init() {
	return
	var err error
	// 使用json反序列化
	dbConnectionMap := make(map[string]interface{})
	if err = json.Unmarshal([]byte(config.DBConnectionString), &dbConnectionMap); err != nil {
		panic(fmt.Errorf("反序列化数据库配置%s的内容出错,错误信息为:%s", config.DBConnectionString, err))
	}

	// 解析出数据库的连接字符串
	var gameDBConnection string
	var gameModelDBConnection string
	if config.DEBUG {
		gameDBConnection = config.GameDBConnection
		gameModelDBConnection = config.GameModelDBConnection
	} else {
		gameDBConnection, err = configUtil.ReadStringJsonValue(dbConnectionMap, "GameDB")
		if err != nil {
			panic(fmt.Errorf("数据库连接字符串中不存在名为%s的配置", "GameDB"))
		}
		gameModelDBConnection, err = configUtil.ReadStringJsonValue(dbConnectionMap, "GameModelDB")
		if err != nil {
			panic(fmt.Errorf("数据库连接字符串中不存在名为%s的配置", "GameModelDB"))
		}
	}

	// 打开数据库连接
	GameDB = openMysqlConnection(gameDBConnection)
	GameModelDB = openMysqlConnection(gameModelDBConnection)

	// 启动一个Goroutine一直ping数据库,以免被数据库认为过期而关掉
	go ping()
}
Exemplo n.º 3
0
func init() {
	// 设置日志文件的存储目录
	logUtil.SetLogPath(filepath.Join(fileUtil.GetCurrentPath(), "LOG"))

	var err error

	// 读取配置文件内容
	config, err := configUtil.ReadJsonConfig(CONFIG_FILE_NAME)
	checkError(err)

	ServerGroupId, err = configUtil.ReadIntJsonValue(config, "ServerGroupId")
	checkError(err)
	ServerActivateUrl, err = configUtil.ReadStringJsonValue(config, "ServerActivateUrl")
	checkError(err)
	GameDBConnection, err = configUtil.ReadStringJsonValue(config, "GameDBConnection")
	checkError(err)
	GameModelDBConnection, err = configUtil.ReadStringJsonValue(config, "GameModelDBConnection")
	checkError(err)
	DEBUG, err = configUtil.ReadBoolJsonValue(config, "DEBUG")
	checkError(err)

	// 激活服务器
	err = manageUtil.ActivateServer(ServerActivateUrl, ServerGroupId)
	if err != nil {
		checkError(fmt.Errorf("激活服务器失败,错误信息为:", err))
	}

	DBConnectionString = manageUtil.GetDBConnectionString()
}
Exemplo n.º 4
0
func init() {
	var err error

	// 读取配置文件内容
	config, err := configUtil.ReadJsonConfig(CONFIG_FILE_NAME)
	checkError(err)

	// 解析AppId
	mAppId, err = configUtil.ReadStringJsonValue(config, "AppId")
	checkError(err)
}