v2ray-core/common/protocol/user_json.go

22 lines
403 B
Go
Raw Normal View History

// +build json
package protocol
2016-05-28 13:44:11 +02:00
import "encoding/json"
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"`
}
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)
return nil
}