config.go 1.03 KB
package confapi

import (
	"apigame/configs/confbase"
	"apigame/service-common/svconst"
	"fmt"
)

// ApiGameConfig api游戏配置
type ApiGameConfig struct {
	Raw *Raw
}

func (c *ApiGameConfig) GetUid() string {
	return c.Raw.GameId
}

func (c *ApiGameConfig) CheckCurrent() bool {
	return true
}

func (c *ApiGameConfig) ConfInfo(suffix string) *confbase.ConfInfo {
	tableName := "s_game_config"
	cacheKey := fmt.Sprintf("%s:%s:%s", svconst.REDIS_CACHEP_REFIX, tableName, suffix)
	return &confbase.ConfInfo{
		DbMysql:      svconst.DbApi,
		TableName:    tableName,
		KeyName:      "gameid",
		CacheKey:     cacheKey,
		CacheCurrent: cacheKey + ":current",
		CacheTime:    300,
	}
}

// Raw 配置原始数据
type Raw 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"`
}

// Decode 解析配置原始数据
func (c *ApiGameConfig) Decode(gameId string, rawData any) {
	raw := rawData.(*Raw)
	c.Raw = raw
}