初始化项目
This commit is contained in:
97
trunk/center/common/configsYaml/baseConfig.go
Normal file
97
trunk/center/common/configsYaml/baseConfig.go
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
配置包,提供项目的配置信息
|
||||
*/
|
||||
package configYaml
|
||||
|
||||
import (
|
||||
"goutil/debugUtil"
|
||||
)
|
||||
|
||||
var (
|
||||
// 是否是DEBUG模式
|
||||
DEBUG bool
|
||||
|
||||
// web服务监听端口
|
||||
WebServerAddress string
|
||||
|
||||
// gRpc监听地址和端口(内网地址即可)
|
||||
GrpcServerAddress string
|
||||
|
||||
// 战斗服务器地址
|
||||
FightServerAddress string
|
||||
|
||||
// 战区Id
|
||||
BigGroupId int
|
||||
|
||||
// 页签Id
|
||||
TagId int
|
||||
|
||||
// 是否是中心服务器地址
|
||||
PlayerServerCenter bool
|
||||
|
||||
// 数据中心服务器地址
|
||||
DataCenterAddress string
|
||||
|
||||
// es urls
|
||||
EsUrls string
|
||||
|
||||
BaseDay int
|
||||
)
|
||||
|
||||
// initBaseConfig
|
||||
// @description: 初始化基础配置数据
|
||||
// parameter:
|
||||
// @configObj: 基础配置数据
|
||||
// return:
|
||||
// @error: 错误信息
|
||||
func initBaseConfig() {
|
||||
|
||||
root := ConfigYaml.Root
|
||||
|
||||
// 为DEBUG模式赋值
|
||||
DEBUG = root.Debug
|
||||
|
||||
// 设置debugUtil的状态
|
||||
debugUtil.SetDebug(DEBUG)
|
||||
|
||||
// 解析rpcConfig配置
|
||||
WebServerAddress = root.WebServerAddress
|
||||
|
||||
// gRpc监听地址和端口(内网地址即可)
|
||||
GrpcServerAddress = root.GrpcServerAddress
|
||||
|
||||
// 解析BigGroupId配置
|
||||
BigGroupId = root.BigGroupId
|
||||
|
||||
// 解析FightServerAddress配置
|
||||
FightServerAddress = root.FightServerAddress
|
||||
|
||||
EsUrls = root.EsUrls
|
||||
|
||||
BaseDay = root.BaseDay
|
||||
}
|
||||
|
||||
// GetDebug
|
||||
// @description: 获取是否是开发环境
|
||||
// parameter:
|
||||
// return:
|
||||
// @bool:
|
||||
func GetDebug() bool {
|
||||
return ConfigYaml.Root.Debug
|
||||
}
|
||||
|
||||
// GetWebServerAddress 返回Web服务器的地址。
|
||||
// 该函数通过访问ConfigYaml中的配置信息,获取并返回Web服务器的地址。
|
||||
// 主要用于需要与Web服务器建立连接的场景。
|
||||
func GetWebServerAddress() string {
|
||||
return ConfigYaml.Root.WebServerAddress
|
||||
}
|
||||
|
||||
// GetEsUrls 返回配置文件中 Elasticsearch 的 URL 地址。
|
||||
//
|
||||
// 该函数通过访问全局变量 ConfigYaml,获取其 Root 字段下的 EsUrls 属性,
|
||||
// 并将其作为字符串返回。这提供了一种简单的方法来获取 Elasticsearch 数据库的连接信息,
|
||||
// 而无需直接访问配置文件。
|
||||
func GetEsUrls() string {
|
||||
return ConfigYaml.Root.EsUrls
|
||||
}
|
||||
154
trunk/center/common/configsYaml/configYaml.go
Normal file
154
trunk/center/common/configsYaml/configYaml.go
Normal file
@@ -0,0 +1,154 @@
|
||||
package configYaml
|
||||
|
||||
var ConfigYaml = Config{}
|
||||
|
||||
// Config 定义与 YAML 文件结构匹配的结构体
|
||||
type Config struct {
|
||||
Root Root
|
||||
}
|
||||
|
||||
// Root 是整个配置文件的根结构体
|
||||
type Root struct {
|
||||
// 是否是调试模式
|
||||
Debug bool `yaml:"debug"`
|
||||
|
||||
// 是否是 CrossServer 中心节点(标记为 true 时,才会进行排行榜处理)
|
||||
CrossServerCenter bool `yaml:"cross_server_center"`
|
||||
|
||||
// ManagerCenter 配置
|
||||
ManagerCenterConfig ManagerCenterConf `yaml:"manager_center_config"`
|
||||
|
||||
// logmgr 配置
|
||||
LogMgr LogMgr `yaml:"log_mgr"`
|
||||
|
||||
// Web 服务监听地址和端口
|
||||
WebServerAddress string `yaml:"web_server_address"`
|
||||
|
||||
// gRPC 监听地址和端口 (内网地址即可)
|
||||
GrpcServerAddress string `yaml:"grpc_server_address"`
|
||||
|
||||
// 战斗服务器地址
|
||||
FightServerAddress string `yaml:"fight_server_address"`
|
||||
|
||||
// 数据中心地址
|
||||
DataCenterAddress string `yaml:"data_center_address"`
|
||||
|
||||
// OrderId 和 BigGroupId(仅用于非 PlayerServer)
|
||||
OrderId int `yaml:"order_id"`
|
||||
BigGroupId int `yaml:"big_group_id"`
|
||||
|
||||
// 重启时载入 Redis 数据日期范围
|
||||
BaseDay int `yaml:"base_day"`
|
||||
|
||||
// ES 地址
|
||||
EsUrls string `yaml:"es_urls"`
|
||||
|
||||
// 数据库配置
|
||||
DbConfig DBConfig `yaml:"db_config"`
|
||||
|
||||
// 监控相关配置
|
||||
MonitorConfig MonitorConf `yaml:"monitor_config"`
|
||||
|
||||
// 功能开关配置
|
||||
FunctionConfig FunctionConf `yaml:"function_config"`
|
||||
}
|
||||
|
||||
// ManagerCenterConf 是 ManagerCenter 的配置结构体
|
||||
type ManagerCenterConf struct {
|
||||
// ManagerCenter API 的 URL
|
||||
ManageCenterAPIUrl string `yaml:"manage_center_api_url"`
|
||||
|
||||
// 服务器组类型
|
||||
GroupType string `yaml:"group_type"`
|
||||
|
||||
// 刷新间隔,单位:分钟
|
||||
RefreshInterval int `yaml:"refresh_interval"`
|
||||
}
|
||||
|
||||
// LogMgr 是日志管理器的配置结构体
|
||||
type LogMgr struct {
|
||||
// group boxId
|
||||
GroupId string `yaml:"group_id"`
|
||||
|
||||
// group secret
|
||||
GroupSecret string `yaml:"group_secret"`
|
||||
|
||||
// product boxId
|
||||
ProductId string `yaml:"product_id"`
|
||||
}
|
||||
|
||||
// DBConfig 包含数据库和 Redis 的配置
|
||||
type DBConfig struct {
|
||||
|
||||
//管理员数据库配置
|
||||
AdminDB DatabaseConfig `yaml:"admin_db"`
|
||||
|
||||
// 用户数据库配置
|
||||
UserDB DatabaseConfig `yaml:"user_db"`
|
||||
|
||||
// 游戏模型数据库配置
|
||||
GameModel DatabaseConfig `yaml:"game_model"`
|
||||
|
||||
// 游戏数据库配置
|
||||
GameDB DatabaseConfig `yaml:"game_db"`
|
||||
|
||||
// 玩家数据库配置
|
||||
PlayerDB DatabaseConfig `yaml:"player_db"`
|
||||
|
||||
// Redis 配置
|
||||
RedisConfig RedisConfig `yaml:"redis_config"`
|
||||
}
|
||||
|
||||
// DatabaseConfig 是数据库连接的配置结构体
|
||||
type DatabaseConfig struct {
|
||||
// 最大处于开启状态的连接数
|
||||
MaxOpenConns int `yaml:"max_open_conns"`
|
||||
|
||||
// 最大处于空闲状态的连接数
|
||||
MaxIdleConns int `yaml:"max_idle_conns"`
|
||||
|
||||
// 数据库连接字符串
|
||||
ConnectionString string `yaml:"connection_string"`
|
||||
}
|
||||
|
||||
// RedisConfig 是 Redis 连接的配置结构体
|
||||
type RedisConfig struct {
|
||||
// Redis 数据库连接字符串
|
||||
ConnectionString string `yaml:"connection_string"`
|
||||
|
||||
// 密码, 如果要设置用户 Id,则密码设置为: "UserId:Password"
|
||||
Password string `yaml:"password"`
|
||||
|
||||
// 数据库序号
|
||||
Database int `yaml:"database"`
|
||||
|
||||
// 最大活跃连接数
|
||||
MaxActive int `yaml:"max_active"`
|
||||
|
||||
// 最大空闲的连接数
|
||||
MaxIdle int `yaml:"max_idle"`
|
||||
|
||||
// 连接空闲超时时间,单位:秒
|
||||
IdleTimeout int `yaml:"idle_timeout"`
|
||||
|
||||
// 连接超时时间, 单位:秒
|
||||
DialConnectTimeout int `yaml:"dial_connect_timeout"`
|
||||
}
|
||||
|
||||
// MonitorConf 是监控配置的结构体
|
||||
type MonitorConf struct {
|
||||
// 监控使用的服务器 IP (本机的外网地址)
|
||||
ServerIP string `yaml:"server_ip"`
|
||||
|
||||
// 监控使用的服务器名称
|
||||
ServerName string `yaml:"server_name"`
|
||||
|
||||
// 监控的时间间隔(单位:分钟)
|
||||
Interval int `yaml:"interval"`
|
||||
}
|
||||
|
||||
// FunctionConf 是功能开关配置的结构体
|
||||
type FunctionConf struct {
|
||||
// 游戏代码: qyc, xh, dzz
|
||||
GameCode string `yaml:"game_code"`
|
||||
}
|
||||
188
trunk/center/common/configsYaml/dbConfig.go
Normal file
188
trunk/center/common/configsYaml/dbConfig.go
Normal file
@@ -0,0 +1,188 @@
|
||||
package configYaml
|
||||
|
||||
import (
|
||||
"goutil/logUtilPlus"
|
||||
"goutil/mysqlUtil"
|
||||
"goutil/redisUtil"
|
||||
"time"
|
||||
)
|
||||
|
||||
// DbConfig
|
||||
//
|
||||
// @description: mysql配置对象
|
||||
type DbConfig struct {
|
||||
|
||||
// 管理员数据库链接字符串
|
||||
adminConfig *mysqlUtil.DBConfig
|
||||
|
||||
// 用户数据库链接字符串
|
||||
userConfig *mysqlUtil.DBConfig
|
||||
|
||||
// 游戏模型数据库链接字符串
|
||||
gameModelConfig *mysqlUtil.DBConfig
|
||||
|
||||
// 游戏数据库链接字符串
|
||||
gameConfig *mysqlUtil.DBConfig
|
||||
|
||||
// 游戏数据库链接字符串
|
||||
playerConfig *mysqlUtil.DBConfig
|
||||
|
||||
// redis配置对象
|
||||
redisConfig *redisUtil.RedisConfig
|
||||
}
|
||||
|
||||
var (
|
||||
// 数据库配置对象
|
||||
dbConfigObj *DbConfig
|
||||
)
|
||||
|
||||
// GetAdminConfig
|
||||
// @description: 获取admin库配置
|
||||
// parameter:
|
||||
//
|
||||
// @receiver config:config
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @*mysqlUtil.DBConfig:admin库配置
|
||||
func (config *DbConfig) GetAdminConfig() *mysqlUtil.DBConfig {
|
||||
return config.adminConfig
|
||||
}
|
||||
|
||||
// GetUserConfig
|
||||
// @description: 获取user库配置
|
||||
// parameter:
|
||||
//
|
||||
// @receiver config:config
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @*mysqlUtil.DBConfig:user库配置
|
||||
func (config *DbConfig) GetUserConfig() *mysqlUtil.DBConfig {
|
||||
return config.userConfig
|
||||
}
|
||||
|
||||
// GetGameModelConfig
|
||||
// @description: 获取model库配置
|
||||
// parameter:
|
||||
//
|
||||
// @receiver config:config
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @*mysqlUtil.DBConfig:model库配置
|
||||
func (config *DbConfig) GetGameModelConfig() *mysqlUtil.DBConfig {
|
||||
return config.gameModelConfig
|
||||
}
|
||||
|
||||
// GetGameConfig
|
||||
// @description: 获取Game库配置
|
||||
// parameter:
|
||||
//
|
||||
// @receiver config:config
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @*mysqlUtil.DBConfig:Game库配置
|
||||
func (config *DbConfig) GetGameConfig() *mysqlUtil.DBConfig {
|
||||
return config.gameConfig
|
||||
}
|
||||
|
||||
// GetPlayerConfig
|
||||
// @description: 获取玩家库配置
|
||||
// parameter:
|
||||
//
|
||||
// @receiver config:config
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @*mysqlUtil.DBConfig:玩家库配置
|
||||
func (config *DbConfig) GetPlayerConfig() *mysqlUtil.DBConfig {
|
||||
return config.playerConfig
|
||||
}
|
||||
|
||||
// GetRedisConfig
|
||||
// @description: 获取redis配置对象
|
||||
// parameter:
|
||||
//
|
||||
// @receiver config:config
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @*redisUtil.RedisConfig:redis配置
|
||||
func (config *DbConfig) GetRedisConfig() *redisUtil.RedisConfig {
|
||||
return config.redisConfig
|
||||
}
|
||||
|
||||
// newMysqlConfig
|
||||
//
|
||||
// @description: 创建新的Mysql配置对象
|
||||
//
|
||||
// parameter:
|
||||
//
|
||||
// @_gameModelConfig:
|
||||
// @_gameConfig:
|
||||
// @_playerConfig:
|
||||
// @_redisConfig:
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @*DbConfig:
|
||||
func newMysqlConfig(_adminConfig *mysqlUtil.DBConfig, _userConfig *mysqlUtil.DBConfig, _gameModelConfig *mysqlUtil.DBConfig,
|
||||
_gameConfig *mysqlUtil.DBConfig,
|
||||
_playerConfig *mysqlUtil.DBConfig,
|
||||
_redisConfig *redisUtil.RedisConfig) *DbConfig {
|
||||
return &DbConfig{
|
||||
adminConfig: _adminConfig,
|
||||
userConfig: _userConfig,
|
||||
gameModelConfig: _gameModelConfig,
|
||||
gameConfig: _gameConfig,
|
||||
redisConfig: _redisConfig,
|
||||
playerConfig: _playerConfig,
|
||||
}
|
||||
}
|
||||
|
||||
// initDbConfig
|
||||
//
|
||||
// @description: 初始化数据库配置
|
||||
//
|
||||
// parameter:
|
||||
//
|
||||
// @configObj: 数据库配置
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @error: 错误数据
|
||||
func initDbConfig() error {
|
||||
|
||||
logUtilPlus.DebugLog("开始加载DbConfig")
|
||||
|
||||
redisConfig := ConfigYaml.Root.DbConfig.RedisConfig
|
||||
|
||||
//if redisConfig == nil {
|
||||
// logUtilPlus.DebugLog("redis配置为空")
|
||||
// return nil
|
||||
//}
|
||||
|
||||
// 初始化mysql配置对象
|
||||
dbConfigObj = newMysqlConfig(
|
||||
mysqlUtil.NewDBConfig(ConfigYaml.Root.DbConfig.AdminDB.ConnectionString, ConfigYaml.Root.DbConfig.AdminDB.MaxOpenConns, ConfigYaml.Root.DbConfig.AdminDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(ConfigYaml.Root.DbConfig.UserDB.ConnectionString, ConfigYaml.Root.DbConfig.UserDB.MaxOpenConns, ConfigYaml.Root.DbConfig.UserDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(ConfigYaml.Root.DbConfig.GameModel.ConnectionString, ConfigYaml.Root.DbConfig.GameModel.MaxOpenConns, ConfigYaml.Root.DbConfig.GameModel.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(ConfigYaml.Root.DbConfig.GameDB.ConnectionString, ConfigYaml.Root.DbConfig.GameDB.MaxOpenConns, ConfigYaml.Root.DbConfig.GameDB.MaxIdleConns),
|
||||
mysqlUtil.NewDBConfig(ConfigYaml.Root.DbConfig.PlayerDB.ConnectionString, ConfigYaml.Root.DbConfig.PlayerDB.MaxOpenConns, ConfigYaml.Root.DbConfig.PlayerDB.MaxIdleConns),
|
||||
redisUtil.NewRedisConfig2(redisConfig.ConnectionString, redisConfig.Password, redisConfig.Database, redisConfig.MaxActive, redisConfig.MaxIdle, time.Duration(redisConfig.IdleTimeout)*time.Second, time.Duration(redisConfig.DialConnectTimeout)*time.Second))
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetDbConfig
|
||||
//
|
||||
// @description: 获取mysql配置
|
||||
//
|
||||
// parameter:
|
||||
// return:
|
||||
//
|
||||
// @*DbConfig: mysql配置对象
|
||||
func GetDbConfig() *DbConfig {
|
||||
return dbConfigObj
|
||||
}
|
||||
63
trunk/center/common/configsYaml/functionConfig.go
Normal file
63
trunk/center/common/configsYaml/functionConfig.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package configYaml
|
||||
|
||||
// FunctionConfig
|
||||
//
|
||||
// @description: 功能开关配置
|
||||
type FunctionConfig struct {
|
||||
|
||||
// 游戏代码
|
||||
GameCode string
|
||||
|
||||
// 仙术副本 清理过期房间信息时间 5 分钟
|
||||
MagicCopyTeamOutTime int
|
||||
|
||||
// 请求青瓷的Url
|
||||
QCSdk_Url string
|
||||
|
||||
// 请求青瓷的GameCode
|
||||
QCSdk_GameCode string
|
||||
|
||||
// 请求青瓷的GameId
|
||||
QCSdk_GameId string
|
||||
|
||||
// 请求青瓷的加密signKey
|
||||
QCSdk_SignKey string
|
||||
}
|
||||
|
||||
var (
|
||||
// 功能开关配置对象
|
||||
functionConfigObj *FunctionConfig
|
||||
)
|
||||
|
||||
// initFunctionConfig
|
||||
//
|
||||
// @description: 加载功能开关配置
|
||||
//
|
||||
// parameter:
|
||||
//
|
||||
// @configObj: 开关配置
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @error: 错误信息
|
||||
func initFunctionConfig() error {
|
||||
functionConfigObj = &FunctionConfig{}
|
||||
|
||||
functionConfig := ConfigYaml.Root.FunctionConfig
|
||||
|
||||
functionConfigObj.GameCode = functionConfig.GameCode
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetFunctionConfigObj
|
||||
//
|
||||
// @description: 获取功能开关配置对象
|
||||
//
|
||||
// parameter:
|
||||
// return:
|
||||
//
|
||||
// @*FunctionConfig:
|
||||
func GetFunctionConfigObj() *FunctionConfig {
|
||||
return functionConfigObj
|
||||
}
|
||||
61
trunk/center/common/configsYaml/init.go
Normal file
61
trunk/center/common/configsYaml/init.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package configYaml
|
||||
|
||||
import (
|
||||
"framework/configMgr"
|
||||
"gopkg.in/yaml.v3"
|
||||
"goutil/logUtil"
|
||||
"goutil/yamlUtil"
|
||||
"log"
|
||||
)
|
||||
|
||||
var (
|
||||
// 配置对象
|
||||
|
||||
configManager = configMgr.NewConfigManager()
|
||||
)
|
||||
|
||||
// init
|
||||
//
|
||||
// @description: init
|
||||
//
|
||||
// parameter:
|
||||
// return:
|
||||
func init() {
|
||||
// 设置日志文件的存储目录
|
||||
logUtil.SetLogPath("LOG")
|
||||
|
||||
if err := reloadConfig(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//加载配置
|
||||
initBaseConfig()
|
||||
initDbConfig()
|
||||
initFunctionConfig()
|
||||
initLogMgrConfig()
|
||||
}
|
||||
|
||||
// reloadConfig
|
||||
//
|
||||
// @description: reloadConfig
|
||||
//
|
||||
// parameter:
|
||||
// return:
|
||||
//
|
||||
// @error: 错误信息
|
||||
func reloadConfig() error {
|
||||
|
||||
yamlFile, err := yamlUtil.LoadFromFile("config.yaml")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 解析 YAML 文件
|
||||
err = yaml.Unmarshal(yamlFile, &ConfigYaml)
|
||||
if err != nil {
|
||||
log.Fatalf("Error unmarshalling config file: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
62
trunk/center/common/configsYaml/logMgrConfig.go
Normal file
62
trunk/center/common/configsYaml/logMgrConfig.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package configYaml
|
||||
|
||||
import (
|
||||
"goutil/logUtilPlus"
|
||||
)
|
||||
|
||||
// LogMgrConfig
|
||||
//
|
||||
// @description: logMgr配置对象
|
||||
type LogMgrConfig struct {
|
||||
// 组id
|
||||
GroupId string
|
||||
|
||||
// 组秘钥
|
||||
GroupSecret string
|
||||
|
||||
// 项目id
|
||||
ProductId string
|
||||
}
|
||||
|
||||
var (
|
||||
// logMgr配置对象
|
||||
logMgrConfigObj *LogMgrConfig
|
||||
)
|
||||
|
||||
// initLogMgrConfig
|
||||
//
|
||||
// @description: 初始化LogMgr配置
|
||||
//
|
||||
// parameter:
|
||||
//
|
||||
// @configObj:
|
||||
//
|
||||
// return:
|
||||
//
|
||||
// @error: 错误信息
|
||||
func initLogMgrConfig() error {
|
||||
|
||||
logUtilPlus.DebugLog("开始加载LogMgr")
|
||||
|
||||
logMgr := ConfigYaml.Root.LogMgr
|
||||
|
||||
logMgrConfigObj = &LogMgrConfig{
|
||||
GroupId: logMgr.GroupId,
|
||||
GroupSecret: logMgr.GroupSecret,
|
||||
ProductId: logMgr.ProductId,
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetLogMgrConfig
|
||||
//
|
||||
// @description: 获取游戏模型数据库链接字符串
|
||||
//
|
||||
// parameter:
|
||||
// return:
|
||||
//
|
||||
// @*LogMgrConfig: 游戏模型数据库链接字符串
|
||||
func GetLogMgrConfig() *LogMgrConfig {
|
||||
return logMgrConfigObj
|
||||
}
|
||||
Reference in New Issue
Block a user