49 lines
954 B
Go
49 lines
954 B
Go
![]() |
package model
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"github.com/go-redis/redis/v8"
|
||
|
"samba/pkg/log"
|
||
|
"samba/stub"
|
||
|
"strconv"
|
||
|
)
|
||
|
|
||
|
type EmoteConfigOp struct {
|
||
|
rdb *redis.Client
|
||
|
key string
|
||
|
}
|
||
|
|
||
|
func NewEmoteConfigOp() *EmoteConfigOp {
|
||
|
return &EmoteConfigOp{rdb: rdbConfig, key: "item_pay_key"}
|
||
|
}
|
||
|
|
||
|
func (t *EmoteConfigOp) Load() {
|
||
|
mapValues, err := t.rdb.HGetAll(context.Background(), t.key).Result()
|
||
|
if err != nil {
|
||
|
log.Error(err.Error())
|
||
|
return
|
||
|
}
|
||
|
if len(mapValues) == 0 {
|
||
|
log.Error(fmt.Sprintf("key:%v does not exist", t.key))
|
||
|
return
|
||
|
}
|
||
|
|
||
|
for k, v := range mapValues {
|
||
|
emoteId, err := strconv.Atoi(k)
|
||
|
if err != nil {
|
||
|
log.Error(fmt.Sprintf("emoteId:%v type not int, err:%v", k, err))
|
||
|
continue
|
||
|
}
|
||
|
emoteItem := &stub.EmoteItem{}
|
||
|
err = json.Unmarshal([]byte(v), &emoteItem)
|
||
|
if err != nil {
|
||
|
log.Error(fmt.Sprintf("%v can not unmarshal, err:%v", v, err))
|
||
|
continue
|
||
|
}
|
||
|
stub.GPayEmote[emoteId] = emoteItem
|
||
|
}
|
||
|
return
|
||
|
}
|