package confglobal import ( "apigame/configs-db/confbase" "apigame/service-common/svconst" "apigame/util/util-lx/lxalilog" "encoding/json" "fmt" ) // GlobalConfig 全局配置 type GlobalConfig struct { Raw *Raw `json:"-"` Names []string Avatars []string AvatarPath string } func (c *GlobalConfig) GetUid() string { return c.Raw.GameId } func (c *GlobalConfig) CheckCurrent() bool { return true } func (c *GlobalConfig) ConfInfo(suffix string) *confbase.ConfInfo { tableName := "s_game_global_config" cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix) return &confbase.ConfInfo{ DbMysql: svconst.DbConfig, TableName: tableName, KeyName: "gameid", CacheKey: cacheKey, CacheCurrent: cacheKey + ":current", CacheTime: 300, } } // Raw 配置原始数据 type Raw struct { GameId string `gorm:"column:gameid"` NameConfig string AvatarConfig string AvatarPath string } // Decode 解析配置原始数据 func (c *GlobalConfig) Decode(gameId string, rawData any) { raw := rawData.(*Raw) c.Raw = raw { err := json.Unmarshal([]byte(raw.NameConfig), &c.Names) if err != nil { lxalilog.Errors(err, raw.NameConfig, gameId, raw.GameId) return } } { err := json.Unmarshal([]byte(raw.AvatarConfig), &c.Avatars) if err != nil { lxalilog.Errors(err, raw.AvatarConfig, gameId, raw.GameId) return } } c.AvatarPath = raw.AvatarPath }