43 lines
821 B
Go
43 lines
821 B
Go
![]() |
package model
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"encoding/json"
|
||
|
"github.com/go-redis/redis/v8"
|
||
|
"samba/pkg/log"
|
||
|
"samba/stub"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
type GamePlayTypeConfigOp struct {
|
||
|
rdb *redis.Client
|
||
|
key string
|
||
|
}
|
||
|
|
||
|
func NewGamePlayTypeConfigOp() *GamePlayTypeConfigOp {
|
||
|
return &GamePlayTypeConfigOp{rdb: rdbConfig, key: "gametypeconfig"}
|
||
|
}
|
||
|
|
||
|
func (t *GamePlayTypeConfigOp) Load() {
|
||
|
table, err := t.rdb.HGetAll(context.Background(), t.key).Result()
|
||
|
if err != nil {
|
||
|
log.Error(err.Error())
|
||
|
return
|
||
|
}
|
||
|
playType := int64(0)
|
||
|
for k, v := range table {
|
||
|
playType, err = strconv.ParseInt(k, 10, 64)
|
||
|
if err != nil {
|
||
|
log.Error(err.Error())
|
||
|
continue
|
||
|
}
|
||
|
pt := &stub.GamePlayType{}
|
||
|
if err = json.Unmarshal([]byte(v), pt); err != nil {
|
||
|
log.Error(err.Error())
|
||
|
continue
|
||
|
}
|
||
|
stub.GamePlayTypes[int(playType)] = pt
|
||
|
}
|
||
|
return
|
||
|
}
|