From 23f685c447a2490c6e338038d1b902b79146ff7f Mon Sep 17 00:00:00 2001 From: 王家文 Date: Thu, 18 Apr 2024 14:15:09 +0800 Subject: [PATCH] feat✨:游戏功能配置 --- configs/conf-api.go | 33 --------------------------------- configs/confapi/config.go | 33 +++++++++++++++++++++++++++++++++ configs/confapi/get.go | 30 ++++++++++++++++++++++++++++++ configs/init.go | 7 +++++-- configs/registry.go | 22 ---------------------- middleware/sign/index.go | 8 ++++---- 6 files changed, 72 insertions(+), 61 deletions(-) delete mode 100644 configs/conf-api.go create mode 100644 configs/confapi/config.go create mode 100644 configs/confapi/get.go diff --git a/configs/conf-api.go b/configs/conf-api.go deleted file mode 100644 index 3f33dfe..0000000 --- a/configs/conf-api.go +++ /dev/null @@ -1,33 +0,0 @@ -package configs - -import ( - "apigame/service-common/svconst" - "apigame/service-common/svmysql" - "apigame/service-common/svredis" - "fmt" -) - -// ApiGameConfig api游戏配置 -type ApiGameConfig struct { - AppId string `gorm:"column:appid"` - GameId string `gorm:"column:gameid"` - Secret string `gorm:"column:secret"` - AppKey string `gorm:"column:appkey"` - Name string `gorm:"column:name"` -} - -func (c *ApiGameConfig) RedisInfo(suffix string) *svredis.RedisInfo { - tableName := "s_game_config" - return &svredis.RedisInfo{ - CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix), - CacheTime: 300, - } -} - -func (c *ApiGameConfig) MysqlInfo(suffix string) *svmysql.MysqlInfo { - tableName := "s_game_config" - return &svmysql.MysqlInfo{ - DbMysql: svconst.DbApi.Where("gameid = ?", suffix), - TableName: tableName, - } -} diff --git a/configs/confapi/config.go b/configs/confapi/config.go new file mode 100644 index 0000000..406f0d4 --- /dev/null +++ b/configs/confapi/config.go @@ -0,0 +1,33 @@ +package confapi + +import ( + "apigame/service-common/svconst" + "apigame/service-common/svmysql" + "apigame/service-common/svredis" + "fmt" +) + +// ApiGameConfig api游戏配置 +type ApiGameConfig struct { + AppId string `gorm:"column:appid"` + GameId string `gorm:"column:gameid"` + Secret string `gorm:"column:secret"` + AppKey string `gorm:"column:appkey"` + Name string `gorm:"column:name"` +} + +func (c *ApiGameConfig) RedisInfo(suffix string) *svredis.RedisInfo { + tableName := "s_game_config" + return &svredis.RedisInfo{ + CacheKey: fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix), + CacheTime: 300, + } +} + +func (c *ApiGameConfig) MysqlInfo(suffix string) *svmysql.MysqlInfo { + tableName := "s_game_config" + return &svmysql.MysqlInfo{ + DbMysql: svconst.DbApi.Where("gameid = ?", suffix), + TableName: tableName, + } +} diff --git a/configs/confapi/get.go b/configs/confapi/get.go new file mode 100644 index 0000000..184f2a6 --- /dev/null +++ b/configs/confapi/get.go @@ -0,0 +1,30 @@ +package confapi + +import ( + "apigame/service-common/svmysql" + "apigame/service-common/svredis" + "apigame/util/util-lx/lxalilog" + "fmt" +) + +// GetConfig 获取 api游戏配置 +func GetConfig(gameId string) (conf *ApiGameConfig, err error) { + conf = new(ApiGameConfig) + has := svredis.LoadData(gameId, conf) + if has { + fmt.Println("dwjw confapi.GetConfig use cache") + return + } + has, err = svmysql.First(conf, gameId) + if err != nil { + lxalilog.Errors(err, "confapi.GetConfig error", gameId) + return + } + if !has { + return + } + fmt.Println("dwjw confapi.GetConfig save cache") + svredis.SaveData(gameId, conf) + + return +} diff --git a/configs/init.go b/configs/init.go index 8aba420..dc3f922 100644 --- a/configs/init.go +++ b/configs/init.go @@ -1,11 +1,14 @@ package configs -import "apigame/service-common/svconst" +import ( + "apigame/configs/confapi" + "apigame/service-common/svconst" +) func Init() bool { for _, gameId := range svconst.GameList { - _, _ = GetApiGameConfig(gameId) + _, _ = confapi.GetConfig(gameId) } for _, gameId := range svconst.GameListCardHolder { diff --git a/configs/registry.go b/configs/registry.go index 80e6a62..f9b764f 100644 --- a/configs/registry.go +++ b/configs/registry.go @@ -7,28 +7,6 @@ import ( "fmt" ) -// GetApiGameConfig 获取 api游戏配置 -func GetApiGameConfig(gameId string) (conf *ApiGameConfig, err error) { - conf = new(ApiGameConfig) - has := svredis.LoadData(gameId, conf) - if has { - fmt.Println("dwjw GetApiGameConfig use cache") - return - } - has, err = svmysql.First(conf, gameId) - if err != nil { - lxalilog.Errors(err, "configs.GetApiGameConfig error", gameId) - return - } - if !has { - return - } - fmt.Println("dwjw GetApiGameConfig save cache") - svredis.SaveData(gameId, conf) - - return -} - // GetCardActivityConfig 获取 卡牌活动配置 func GetCardActivityConfig(gameId string) (conf *CardActivityConfig, has bool) { var err error diff --git a/middleware/sign/index.go b/middleware/sign/index.go index 6347ea0..c658cec 100644 --- a/middleware/sign/index.go +++ b/middleware/sign/index.go @@ -1,7 +1,7 @@ package sign import ( - "apigame/configs" + "apigame/configs/confapi" "apigame/middleware/sdk" "apigame/service/code-msg" "apigame/util/util-lx/lxalilog" @@ -59,7 +59,7 @@ func getTimeStamp(time_stamp interface{}) (timestamp int64) { } -func InitCheck(postdata interface{}, cgg MCheckConfig) (code string, gameconfig *configs.ApiGameConfig, err error) { +func InitCheck(postdata interface{}, cgg MCheckConfig) (code string, gameconfig *confapi.ApiGameConfig, err error) { var ( postGameId string @@ -195,7 +195,7 @@ func Check(req []byte, postdata interface{}, checkSign bool, checkToken bool) (c } // CheckSign 校验签名 -func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *configs.ApiGameConfig, err error) { +func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *confapi.ApiGameConfig, err error) { var ( logstr string @@ -223,7 +223,7 @@ func CheckSign(data interface{}, checkToken bool) (code string, gameconfig *conf gameid := newdata["gameid"].(string) - gameconfig, err = configs.GetApiGameConfig(gameid) + gameconfig, err = confapi.GetConfig(gameid) if err != nil { lxalilog.Errors(err) return -- libgit2 0.21.0