feat(config): 添加RPC端口和游戏端口配置项 在配置结构体中新增了RPC端口和游戏端口字段,并更新了配置文件以支持多端口监听。同时, 调整了服务器端口选择逻辑,优先使用默认端口,不再生成随机端口。 refactor(server): 移除随机端口生成逻辑 删除了随机端口生成及相关依赖,端口选择改为从预定义列表中查找可用端口,提高端口分配的 可控性和稳定性。 fix(fight): 注释掉未实现的panic语句 为避免程序运行时因未实现逻辑导致崩溃,注释掉了Turn_Start和Fight_Start中的panic调用, 并添加了相关注释说明后续需实现的内容。 chore(config): 更新默认配置参数 更新了服务器地址、端口、数据库连接信息及Redis配置,确保开发环境配置正确。 ```
75 lines
2.8 KiB
Go
75 lines
2.8 KiB
Go
package coolconfig
|
|
|
|
import "github.com/gogf/gf/v2/frame/g"
|
|
|
|
// cool config
|
|
type sConfig struct {
|
|
AutoMigrate bool `json:"auto_migrate,omitempty"` // 是否自动创建表
|
|
Eps bool `json:"eps,omitempty"` // 是否开启eps
|
|
File *file `json:"file,omitempty"` // 文件上传配置
|
|
Name string `json:"name"` // 项目名称
|
|
Port string `json:"port"`
|
|
PortBL uint16 `json:"port_bl"` //这个是命令行输入的参数
|
|
RPC uint16 //rpc端口
|
|
GamePort []uint64
|
|
}
|
|
|
|
// OSS相关配置
|
|
type oss struct {
|
|
Endpoint string `json:"endpoint"`
|
|
AccessKeyID string `json:"accessKeyID"`
|
|
SecretAccessKey string `json:"secretAccessKey"`
|
|
UseSSL bool `json:"useSSL"`
|
|
BucketName string `json:"bucketName"`
|
|
Location string `json:"location"`
|
|
}
|
|
|
|
// 文件上传配置
|
|
type file struct {
|
|
Mode string `json:"mode"` // 模式 local oss
|
|
Domain string `json:"domain"` // 域名 http://
|
|
Oss *oss `json:"oss,omitempty"`
|
|
}
|
|
|
|
// NewConfig new config
|
|
func newConfig() *sConfig {
|
|
var ctx g.Ctx
|
|
config := &sConfig{
|
|
AutoMigrate: GetCfgWithDefault(ctx, "blazing.autoMigrate", g.NewVar(false)).Bool(),
|
|
Name: GetCfgWithDefault(ctx, "server.name", g.NewVar("")).String(),
|
|
Eps: GetCfgWithDefault(ctx, "blazing.eps", g.NewVar(false)).Bool(),
|
|
Port: string(GetCfgWithDefault(ctx, "server.port", g.NewVar("8080")).String()),
|
|
RPC: GetCfgWithDefault(ctx, "server.rpc", g.NewVar("8080")).Uint16(),
|
|
GamePort: GetCfgWithDefault(ctx, "server.game", g.NewVar("8080")).Uint64s(),
|
|
|
|
File: &file{
|
|
Mode: GetCfgWithDefault(ctx, "blazing.file.mode", g.NewVar("none")).String(),
|
|
Domain: GetCfgWithDefault(ctx, "blazing.file.domain", g.NewVar("http://127.0.0.1:8300")).String(),
|
|
Oss: &oss{
|
|
Endpoint: GetCfgWithDefault(ctx, "blazing.file.oss.endpoint", g.NewVar("127.0.0.1:9000")).String(),
|
|
AccessKeyID: GetCfgWithDefault(ctx, "blazing.file.oss.accessKeyID", g.NewVar("")).String(),
|
|
SecretAccessKey: GetCfgWithDefault(ctx, "blazing.file.oss.secretAccessKey", g.NewVar("")).String(),
|
|
UseSSL: GetCfgWithDefault(ctx, "blazing.file.oss.useSSL", g.NewVar(false)).Bool(),
|
|
BucketName: GetCfgWithDefault(ctx, "blazing.file.oss.bucketName", g.NewVar("blazing")).String(),
|
|
Location: GetCfgWithDefault(ctx, "blazing.file.oss.location", g.NewVar("us-east-1")).String(),
|
|
},
|
|
},
|
|
}
|
|
return config
|
|
}
|
|
|
|
// Config config
|
|
var Config = newConfig()
|
|
|
|
// GetCfgWithDefault get config with default value
|
|
func GetCfgWithDefault(ctx g.Ctx, key string, defaultValue *g.Var) *g.Var {
|
|
value, err := g.Cfg().GetWithEnv(ctx, key)
|
|
if err != nil {
|
|
return defaultValue
|
|
}
|
|
if value.IsEmpty() || value.IsNil() {
|
|
return defaultValue
|
|
}
|
|
return value
|
|
}
|