game_sync/ranksrv/com/etcd.go

49 lines
1.4 KiB
Go

package com
import (
"context"
"go.etcd.io/etcd/client/v3"
"mongo.games.com/game/etcd"
"mongo.games.com/game/model"
"mongo.games.com/game/protocol/webapi"
)
var ConfigMgrInst = model.NewConfigMgr()
func init() {
// 平台信息
etcd.Register(etcd.ETCDKEY_PLATFORM_PREFIX, webapi.Platform{}, PlatformConfigEtcd)
// 竞技馆房间配置
etcd.Register(etcd.ETCDKEY_RoomConfig, webapi.RoomConfig{}, PlatformConfigEtcd)
// 抽奖展示
etcd.Register(etcd.ETCDKEY_LotteryShow, webapi.ShowLottery{}, etcdHandler)
}
func PlatformConfigEtcd(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) {
if event.Type == clientv3.EventTypeDelete {
return
}
switch config := data.(type) {
case *webapi.Platform:
PlatformConfigSingleton.Update(config)
case *webapi.RoomConfig:
ConfigMgrInst.UpdateRoomConfig(config)
case *webapi.ShowLottery:
ConfigMgrInst.GetConfig(config.Platform).LotteryShows[config.GetId()] = config
}
}
func etcdHandler(ctx context.Context, completeKey string, isInit bool, event *clientv3.Event, data interface{}) {
switch config := data.(type) {
case *webapi.ShowLottery:
switch event.Type {
case clientv3.EventTypePut:
ConfigMgrInst.GetConfig(config.Platform).LotteryShows[config.GetId()] = config
case clientv3.EventTypeDelete:
delete(ConfigMgrInst.GetConfig(config.Platform).LotteryShows, config.GetId())
}
}
}