1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-01 19:45:24 +00:00
v2fly/common/protocol/user_json.go
2016-05-28 13:44:11 +02:00

30 lines
588 B
Go

// +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
}