Files
backend-server/server/models/users.go
Josef Fröhle 40d569158f remove dumps and trash
add some new files and services

add hwtools that shows the current and last GWs - not yet included the user stats (if any available)
2020-07-07 19:00:49 +02:00

71 lines
1.6 KiB
Go

package models
import (
"encoding/json"
"strconv"
"time"
)
// UnmarshalUserJSON ...
func (u *User) UnmarshalUserJSON(data []byte) error {
var f interface{}
err := json.Unmarshal(data, &f)
if err != nil {
return err
}
m := f.(map[string]interface{})
for k, v := range m {
switch k {
case "allowPm":
u.AllowPm = v.(string)
case "avatarId":
u.AvatarID = v.(string)
case "clanId":
u.ClanID, _ = strconv.ParseUint(v.(string), 10, 64)
case "clanRole":
u.ClanRole = v.(string)
case "clanTitle":
u.ClanTitle = v.(string)
case "id":
u.ID, _ = strconv.ParseUint(v.(string), 10, 64)
case "isChatModerator":
u.IsChatModerator = v.(bool)
case "lastLoginTime":
unixTimeStamp, _ := strconv.ParseInt(v.(string), 10, 64)
u.LastLoginTime = time.Unix(unixTimeStamp, 0)
case "leagueId":
var leagueID *int64
if v != nil {
l := int64(v.(float64))
leagueID = &l
}
u.LeagueID = leagueID
case "level":
u.Level = v.(string)
case "name":
u.Name = v.(string)
case "serverId":
u.ServerID = v.(string)
}
}
return nil
}
// User ...
// used in
// - arenaAttack
type User struct {
ID uint64 `json:"id"`
AllowPm string `json:"allowPm"`
AvatarID string `json:"avatarId"`
ClanID uint64 `json:"clanId"`
ClanRole string `json:"clanRole"`
ClanTitle string `json:"clanTitle"`
IsChatModerator bool `json:"isChatModerator"`
LastLoginTime time.Time `json:"lastLoginTime"`
LeagueID *int64 `json:"leagueId"`
Level string `json:"level"`
Name string `json:"name"`
ServerID string `json:"serverId"`
}