You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
// +build json
|
|
|
|
|
|
|
|
package protocol
|
|
|
|
|
|
|
|
import "encoding/json"
|
|
|
|
|
|
|
|
func (u *User) UnmarshalJSON(data []byte) error {
|
|
|
|
type rawUser struct {
|
|
|
|
EmailString string `json:"email"`
|
|
|
|
LevelByte byte `json:"level"`
|
|
|
|
}
|
|
|
|
var rawUserValue rawUser
|
|
|
|
if err := json.Unmarshal(data, &rawUserValue); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
var rawAccount AccountJson
|
|
|
|
if err := json.Unmarshal(data, &rawAccount); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
account, err := rawAccount.GetAccount()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
*u = *NewUser(account, UserLevel(rawUserValue.LevelByte), rawUserValue.EmailString)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|