2016-01-15 11:43:06 +00:00
|
|
|
// +build json
|
|
|
|
|
2016-02-03 10:58:42 +00:00
|
|
|
package protocol
|
2016-01-15 11:43:06 +00:00
|
|
|
|
2016-05-28 11:44:11 +00:00
|
|
|
import "encoding/json"
|
2016-01-15 11:43:06 +00:00
|
|
|
|
|
|
|
func (u *User) UnmarshalJSON(data []byte) error {
|
|
|
|
type rawUser struct {
|
2016-05-28 11:44:11 +00:00
|
|
|
EmailString string `json:"email"`
|
|
|
|
LevelByte byte `json:"level"`
|
2016-01-15 11:43:06 +00:00
|
|
|
}
|
|
|
|
var rawUserValue rawUser
|
|
|
|
if err := json.Unmarshal(data, &rawUserValue); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-28 11:44:11 +00:00
|
|
|
|
|
|
|
var rawAccount AccountJson
|
|
|
|
if err := json.Unmarshal(data, &rawAccount); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
account, err := rawAccount.GetAccount()
|
2016-01-15 11:43:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-28 11:44:11 +00:00
|
|
|
|
|
|
|
*u = *NewUser(account, UserLevel(rawUserValue.LevelByte), rawUserValue.EmailString)
|
2016-01-15 11:43:06 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|