config.go
1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package confglobal
import (
"apigame/configs/confbase"
"apigame/service-common/svconst"
"apigame/util/util-lx/lxalilog"
"encoding/json"
"fmt"
)
// GlobalConfig 全局配置
type GlobalConfig struct {
Raw *Raw `json:"-"`
Names []string
Avatars []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
}
// 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
}
}
}