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