43 lines
809 B
Go
43 lines
809 B
Go
package model
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"github.com/go-redis/redis/v8"
|
|
"samba/pkg/log"
|
|
"samba/stub"
|
|
"strconv"
|
|
)
|
|
|
|
type ClubRobotConfigOp struct {
|
|
rdb *redis.Client
|
|
key string
|
|
}
|
|
|
|
func NewClubRobotConfigOp() *ClubRobotConfigOp {
|
|
return &ClubRobotConfigOp{rdb: rdbConfig, key: "robot|club"}
|
|
}
|
|
|
|
func (op *ClubRobotConfigOp) Load() {
|
|
table, err := op.rdb.HGetAll(context.Background(), op.key).Result()
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
return
|
|
}
|
|
id := int64(0)
|
|
for k, v := range table {
|
|
id, err = strconv.ParseInt(k, 10, 64)
|
|
if err != nil {
|
|
log.Error(err.Error())
|
|
continue
|
|
}
|
|
clubRobot := &stub.ClubRobotConfig{}
|
|
if err = json.Unmarshal([]byte(v), clubRobot); err != nil {
|
|
log.Error(err.Error())
|
|
continue
|
|
}
|
|
stub.ClubRobotConfigs[id] = clubRobot
|
|
}
|
|
return
|
|
}
|