修改gate address bug

This commit is contained in:
liuxiaobo 2025-05-29 17:34:47 +08:00
parent dccf1e0d69
commit a68dbdd535
2 changed files with 11 additions and 8 deletions

View File

@ -9,17 +9,16 @@ import (
)
const (
gateKey = "gate_config"
gateAddress = "114.132.124.145"
gatePort = "5100"
gateKey = "gate_config"
gateAddress1 = "114.132.124.145:5100"
gateAddress2 = "114.132.124.145:5101"
)
var Command *config.Command
var Cfg *config.Common[GateConfig]
type GateConfig struct {
Address string `json:"address"` // 网关地址
Port string `json:"port"`
Address []string `json:"address"` // 网关地址
}
func initLog() {
@ -43,8 +42,7 @@ func LoadConfig(GitCommit, GitBranch, BuildDate string) {
if err = config.LoadSpecialConfig[GateConfig](rdb, gateKey, Cfg); err != nil {
log.DebugF("load config:empty etcd key")
Cfg.Special = &GateConfig{
Address: gateAddress,
Port: gatePort,
Address: []string{gateAddress1, gateAddress2},
}
if bs, err := json.Marshal(&Cfg.Special); err == nil {
err = rdb.Set(context.Background(), gateKey, string(bs), 0).Err()

View File

@ -65,7 +65,12 @@ func newGateService(serviceId int) *GateService {
return nil
}
wsAddress := fmt.Sprintf("%v:%v", config.Cfg.Special.Address, config.Cfg.Special.Port)
addressPos := serviceId - config.Command.ServiceId
if len(config.Cfg.Special.Address) <= addressPos {
log.FatalF("Special address number must be greater than %d", addressPos)
return nil
}
wsAddress := config.Cfg.Special.Address[addressPos]
s.wss = ws.NewWsServer(wsAddress, s.WsOnMessage, s.WsOnDisconnect)
s.bindService = userBindService.NewUserBindService(model.UserRedis, s.ServiceEtcd())