Commit 23f685c447a2490c6e338038d1b902b79146ff7f

Authored by 王家文
1 parent 2c9d1e53
Exists in master and in 1 other branch dev-wjw

feat✨:游戏功能配置

configs/conf-api.go
@@ -1,33 +0,0 @@ @@ -1,33 +0,0 @@
1 -package configs  
2 -  
3 -import (  
4 - "apigame/service-common/svconst"  
5 - "apigame/service-common/svmysql"  
6 - "apigame/service-common/svredis"  
7 - "fmt"  
8 -)  
9 -  
10 -// ApiGameConfig api游戏配置  
11 -type ApiGameConfig struct {  
12 - AppId string `gorm:"column:appid"`  
13 - GameId string `gorm:"column:gameid"`  
14 - Secret string `gorm:"column:secret"`  
15 - AppKey string `gorm:"column:appkey"`  
16 - Name string `gorm:"column:name"`  
17 -}  
18 -  
19 -func (c *ApiGameConfig) RedisInfo(suffix string) *svredis.RedisInfo {  
20 - tableName := "s_game_config"  
21 - return &svredis.RedisInfo{  
22 - CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix),  
23 - CacheTime: 300,  
24 - }  
25 -}  
26 -  
27 -func (c *ApiGameConfig) MysqlInfo(suffix string) *svmysql.MysqlInfo {  
28 - tableName := "s_game_config"  
29 - return &svmysql.MysqlInfo{  
30 - DbMysql: svconst.DbApi.Where("gameid = ?", suffix),  
31 - TableName: tableName,  
32 - }  
33 -}  
configs/confapi/config.go 0 → 100644
@@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
  1 +package confapi
  2 +
  3 +import (
  4 + "apigame/service-common/svconst"
  5 + "apigame/service-common/svmysql"
  6 + "apigame/service-common/svredis"
  7 + "fmt"
  8 +)
  9 +
  10 +// ApiGameConfig api游戏配置
  11 +type ApiGameConfig struct {
  12 + AppId string `gorm:"column:appid"`
  13 + GameId string `gorm:"column:gameid"`
  14 + Secret string `gorm:"column:secret"`
  15 + AppKey string `gorm:"column:appkey"`
  16 + Name string `gorm:"column:name"`
  17 +}
  18 +
  19 +func (c *ApiGameConfig) RedisInfo(suffix string) *svredis.RedisInfo {
  20 + tableName := "s_game_config"
  21 + return &svredis.RedisInfo{
  22 + CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix),
  23 + CacheTime: 300,
  24 + }
  25 +}
  26 +
  27 +func (c *ApiGameConfig) MysqlInfo(suffix string) *svmysql.MysqlInfo {
  28 + tableName := "s_game_config"
  29 + return &svmysql.MysqlInfo{
  30 + DbMysql: svconst.DbApi.Where("gameid = ?", suffix),
  31 + TableName: tableName,
  32 + }
  33 +}
configs/confapi/get.go 0 → 100644
@@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
  1 +package confapi
  2 +
  3 +import (
  4 + "apigame/service-common/svmysql"
  5 + "apigame/service-common/svredis"
  6 + "apigame/util/util-lx/lxalilog"
  7 + "fmt"
  8 +)
  9 +
  10 +// GetConfig 获取 api游戏配置
  11 +func GetConfig(gameId string) (conf *ApiGameConfig, err error) {
  12 + conf = new(ApiGameConfig)
  13 + has := svredis.LoadData(gameId, conf)
  14 + if has {
  15 + fmt.Println("dwjw confapi.GetConfig use cache")
  16 + return
  17 + }
  18 + has, err = svmysql.First(conf, gameId)
  19 + if err != nil {
  20 + lxalilog.Errors(err, "confapi.GetConfig error", gameId)
  21 + return
  22 + }
  23 + if !has {
  24 + return
  25 + }
  26 + fmt.Println("dwjw confapi.GetConfig save cache")
  27 + svredis.SaveData(gameId, conf)
  28 +
  29 + return
  30 +}
configs/init.go
1 package configs 1 package configs
2 2
3 -import "apigame/service-common/svconst" 3 +import (
  4 + "apigame/configs/confapi"
  5 + "apigame/service-common/svconst"
  6 +)
4 7
5 func Init() bool { 8 func Init() bool {
6 9
7 for _, gameId := range svconst.GameList { 10 for _, gameId := range svconst.GameList {
8 - _, _ = GetApiGameConfig(gameId) 11 + _, _ = confapi.GetConfig(gameId)
9 } 12 }
10 13
11 for _, gameId := range svconst.GameListCardHolder { 14 for _, gameId := range svconst.GameListCardHolder {
configs/registry.go
@@ -7,28 +7,6 @@ import ( @@ -7,28 +7,6 @@ import (
7 "fmt" 7 "fmt"
8 ) 8 )
9 9
10 -// GetApiGameConfig 获取 api游戏配置  
11 -func GetApiGameConfig(gameId string) (conf *ApiGameConfig, err error) {  
12 - conf = new(ApiGameConfig)  
13 - has := svredis.LoadData(gameId, conf)  
14 - if has {  
15 - fmt.Println("dwjw GetApiGameConfig use cache")  
16 - return  
17 - }  
18 - has, err = svmysql.First(conf, gameId)  
19 - if err != nil {  
20 - lxalilog.Errors(err, "configs.GetApiGameConfig error", gameId)  
21 - return  
22 - }  
23 - if !has {  
24 - return  
25 - }  
26 - fmt.Println("dwjw GetApiGameConfig save cache")  
27 - svredis.SaveData(gameId, conf)  
28 -  
29 - return  
30 -}  
31 -  
32 // GetCardActivityConfig 获取 卡牌活动配置 10 // GetCardActivityConfig 获取 卡牌活动配置
33 func GetCardActivityConfig(gameId string) (conf *CardActivityConfig, has bool) { 11 func GetCardActivityConfig(gameId string) (conf *CardActivityConfig, has bool) {
34 var err error 12 var err error
middleware/sign/index.go
1 package sign 1 package sign
2 2
3 import ( 3 import (
4 - "apigame/configs" 4 + "apigame/configs/confapi"
5 "apigame/middleware/sdk" 5 "apigame/middleware/sdk"
6 "apigame/service/code-msg" 6 "apigame/service/code-msg"
7 "apigame/util/util-lx/lxalilog" 7 "apigame/util/util-lx/lxalilog"
@@ -59,7 +59,7 @@ func getTimeStamp(time_stamp interface{}) (timestamp int64) { @@ -59,7 +59,7 @@ func getTimeStamp(time_stamp interface{}) (timestamp int64) {
59 59
60 } 60 }
61 61
62 -func InitCheck(postdata interface{}, cgg MCheckConfig) (code string, gameconfig *configs.ApiGameConfig, err error) { 62 +func InitCheck(postdata interface{}, cgg MCheckConfig) (code string, gameconfig *confapi.ApiGameConfig, err error) {
63 63
64 var ( 64 var (
65 postGameId string 65 postGameId string
@@ -195,7 +195,7 @@ func Check(req []byte, postdata interface{}, checkSign bool, checkToken bool) (c @@ -195,7 +195,7 @@ func Check(req []byte, postdata interface{}, checkSign bool, checkToken bool) (c
195 } 195 }
196 196
197 // CheckSign 校验签名 197 // CheckSign 校验签名
198 -func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *configs.ApiGameConfig, err error) { 198 +func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *confapi.ApiGameConfig, err error) {
199 199
200 var ( 200 var (
201 logstr string 201 logstr string
@@ -223,7 +223,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf @@ -223,7 +223,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf
223 223
224 gameid := newdata["gameid"].(string) 224 gameid := newdata["gameid"].(string)
225 225
226 - gameconfig, err = configs.GetApiGameConfig(gameid) 226 + gameconfig, err = confapi.GetConfig(gameid)
227 if err != nil { 227 if err != nil {
228 lxalilog.Errors(err) 228 lxalilog.Errors(err)
229 return 229 return