2016-01-15 12:43:06 +01:00
|
|
|
// +build json
|
|
|
|
|
2016-02-03 11:58:42 +01:00
|
|
|
package protocol
|
2016-01-15 12:43:06 +01:00
|
|
|
|
2016-05-28 13:44:11 +02:00
|
|
|
import "encoding/json"
|
2016-01-15 12:43:06 +01:00
|
|
|
|
|
|
|
func (u *User) UnmarshalJSON(data []byte) error {
|
|
|
|
type rawUser struct {
|
2016-05-28 13:44:11 +02:00
|
|
|
EmailString string `json:"email"`
|
|
|
|
LevelByte byte `json:"level"`
|
2016-01-15 12:43:06 +01:00
|
|
|
}
|
|
|
|
var rawUserValue rawUser
|
|
|
|
if err := json.Unmarshal(data, &rawUserValue); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-28 13:44:11 +02:00
|
|
|
|
2016-07-25 17:36:24 +02:00
|
|
|
u.Email = rawUserValue.EmailString
|
2016-09-18 00:41:21 +02:00
|
|
|
u.Level = uint32(rawUserValue.LevelByte)
|
2016-01-15 12:43:06 +01:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|