Commit 533598d0c8734e2cb25558ac82e333096bad6bbb
1 parent
2e7e26fd
Exists in
master
and in
1 other branch
refactor♻️:项目目录重构
Showing
6 changed files
with
97 additions
and
0 deletions
Show diff stats
| @@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
| 1 | +package svconfig | ||
| 2 | + | ||
| 3 | +import "gorm.io/gorm" | ||
| 4 | + | ||
| 5 | +const ( | ||
| 6 | + MYSQL_TABLE_TEMPLATE = "all_table_template" // 表名模板 | ||
| 7 | + REDIS_CACHEP_REFIX = "apigame" // 缓存前缀 | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +// ConfigRule 配置数据 | ||
| 11 | +type ConfigRule struct { | ||
| 12 | + DbMysql *gorm.DB | ||
| 13 | + TableNameTemplate string | ||
| 14 | + TableName string | ||
| 15 | + CacheKey string | ||
| 16 | + CacheTime int | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +// IConfigRule 配置数据 | ||
| 20 | +type IConfigRule interface { | ||
| 21 | + // GetRule 表名模板 | ||
| 22 | + GetRule(gameId string) *ConfigRule | ||
| 23 | +} |
| @@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
| 1 | +package configs | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "apigame/common/svconfig" | ||
| 5 | + "apigame/common/svconst" | ||
| 6 | + "apigame/service/constd" | ||
| 7 | + "fmt" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type ApiGameConfig struct { | ||
| 11 | + AppId string `json:"appid"` | ||
| 12 | + GameId string `json:"gameid"` | ||
| 13 | + Secret string `json:"secret"` | ||
| 14 | + AppKey string `json:"appkey"` | ||
| 15 | + Name string `json:"name"` | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (c *ApiGameConfig) GetRule(gameId string) *svconfig.ConfigRule { | ||
| 19 | + tableName := constd.MYSQL_TABLE_S_CARDHOLDER_CONFIG | ||
| 20 | + return &svconfig.ConfigRule{ | ||
| 21 | + DbMysql: svconst.DbApi, | ||
| 22 | + TableNameTemplate: svconfig.MYSQL_TABLE_TEMPLATE, | ||
| 23 | + TableName: tableName + gameId, | ||
| 24 | + CacheKey: fmt.Sprintf("%s::%s::%s", svconfig.REDIS_CACHEP_REFIX, tableName, gameId), | ||
| 25 | + CacheTime: 300, | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +func (c *ApiGameConfig) ReadFromMysql(gameId string) *ApiGameConfig { | ||
| 30 | + rule := c.GetRule(gameId) | ||
| 31 | + | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +func GetApiGameConfig(gameId string) (config *ApiGameConfig, err error) { | ||
| 35 | + //rds := zredis.GetConn() | ||
| 36 | + //zredis.HGetData(rds, player) | ||
| 37 | + return | ||
| 38 | +} |
| @@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
| 1 | +package configs | ||
| 2 | + | ||
| 3 | +import "apigame/common/svconfig" | ||
| 4 | + | ||
| 5 | +func Init() bool { | ||
| 6 | + | ||
| 7 | + return true | ||
| 8 | +} | ||
| 9 | + | ||
| 10 | +func GetConfigRedis[T svconfig.IConfigRule](gameId string) { | ||
| 11 | + | ||
| 12 | +} | ||
| 13 | + | ||
| 14 | +func GetConfigMysql[T svconfig.IConfigRule](gameId string) { | ||
| 15 | + | ||
| 16 | +} |
| @@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
| 1 | +package configs |
main.go
| 1 | package main | 1 | package main |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "apigame/common/svconfig" | ||
| 4 | "apigame/common/svconst" | 5 | "apigame/common/svconst" |
| 5 | "apigame/common/svdto" | 6 | "apigame/common/svdto" |
| 6 | "apigame/common/svlog" | 7 | "apigame/common/svlog" |
| 7 | "apigame/common/svmysql" | 8 | "apigame/common/svmysql" |
| 8 | "apigame/common/svredis" | 9 | "apigame/common/svredis" |
| 10 | + "apigame/configs" | ||
| 9 | _ "apigame/routers" | 11 | _ "apigame/routers" |
| 10 | "apigame/service/cardholder" | 12 | "apigame/service/cardholder" |
| 11 | "github.com/astaxie/beego" | 13 | "github.com/astaxie/beego" |
| @@ -57,6 +59,13 @@ func Init() { | @@ -57,6 +59,13 @@ func Init() { | ||
| 57 | // | 59 | // |
| 58 | //_ = config.InitLxLimit() | 60 | //_ = config.InitLxLimit() |
| 59 | 61 | ||
| 62 | + if !svconfig.Init() { | ||
| 63 | + return | ||
| 64 | + } | ||
| 65 | + if !configs.Init() { | ||
| 66 | + return | ||
| 67 | + } | ||
| 68 | + | ||
| 60 | svdto.Init() | 69 | svdto.Init() |
| 61 | 70 | ||
| 62 | // 初始化配置 | 71 | // 初始化配置 |
util/zredis/kv.go
| @@ -17,3 +17,13 @@ func Increment(key string) int64 { | @@ -17,3 +17,13 @@ func Increment(key string) int64 { | ||
| 17 | } | 17 | } |
| 18 | return 0 | 18 | return 0 |
| 19 | } | 19 | } |
| 20 | + | ||
| 21 | +func Set(conn redis.Conn, key, value string) (err error) { | ||
| 22 | + _, err = conn.Do("Set", key, value) | ||
| 23 | + return | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func Get(conn redis.Conn, key string) (value string, err error) { | ||
| 27 | + value, err = redis.String(conn.Do("Get", "name")) | ||
| 28 | + return | ||
| 29 | +} |