package config import ( "context" "encoding/json" "fmt" "game/common/config" "github.com/fox/fox/db" "github.com/fox/fox/log" ) const ( gateKey = "gate_config" gateAddress = "114.132.124.145" gatePort = "5100" ) var Command *config.Command var Cfg *config.Common[GateConfig] type GateConfig struct { Address string `json:"address"` // 网关地址 Port string `json:"port"` } func initLog() { log.Open(fmt.Sprintf("gate_%v.log", Command.VMod), log.DebugL) } func LoadConfig(GitCommit, GitBranch, BuildDate string) { Command = config.ParseCommand() initLog() rdb, err := db.InitRedis(Command.RedisPassword, Command.RedisHost, Command.RedisPort, 0) if err != nil { log.Error(err.Error()) return } defer func() { _ = rdb.Close() }() Cfg, err = config.LoadCommonConfig[GateConfig](rdb, GitCommit, GitBranch, BuildDate) if err != nil { log.Error(err.Error()) return } if err = config.LoadSpecialConfig[GateConfig](rdb, gateKey, Cfg); err != nil { log.DebugF("load config:empty etcd key") Cfg.Special = &GateConfig{ Address: gateAddress, Port: gatePort, } if bs, err := json.Marshal(&Cfg.Special); err == nil { err = rdb.Set(context.Background(), gateKey, string(bs), 0).Err() } } log.DebugF("load common config success") }