2016-07-06 03:55:05 +05:30
|
|
|
package data
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"encoding/json"
|
|
|
|
|
|
|
|
"elyby/minecraft-skinsystem/lib/services"
|
|
|
|
"elyby/minecraft-skinsystem/lib/tools"
|
|
|
|
)
|
|
|
|
|
|
|
|
type SkinItem struct {
|
|
|
|
UserId int `json:"userId"`
|
|
|
|
Nickname string `json:"nickname"`
|
|
|
|
SkinId int `json:"skinId"`
|
|
|
|
Url string `json:"url"`
|
|
|
|
Is1_8 bool `json:"is1_8"`
|
|
|
|
IsSlim bool `json:"isSlim"`
|
|
|
|
Hash string `json:"hash"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SkinItem) Save() {
|
|
|
|
str, _ := json.Marshal(s)
|
2016-07-08 02:11:21 +05:30
|
|
|
services.Redis.Cmd("SET", tools.BuildKey(s.Nickname), str)
|
2016-07-06 03:55:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func FindRecord(username string) (SkinItem, error) {
|
|
|
|
var record SkinItem;
|
2016-07-08 02:11:21 +05:30
|
|
|
result, err := services.Redis.Cmd("GET", tools.BuildKey(username)).Str();
|
2016-07-06 03:55:05 +05:30
|
|
|
if (err == nil) {
|
|
|
|
decodeErr := json.Unmarshal([]byte(result), &record)
|
|
|
|
if (decodeErr != nil) {
|
|
|
|
log.Println("Cannot decode record data")
|
|
|
|
}
|
2016-07-28 20:47:12 +05:30
|
|
|
} else {
|
|
|
|
log.Println("Error on request user data")
|
2016-07-06 03:55:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return record, err
|
|
|
|
}
|