v2ray-core/common/protocol/user_json.go

22 lines
406 B
Go
Raw Normal View History

// +build json
package protocol
2016-05-28 11:44:11 +00:00
import "encoding/json"
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"`
}
var rawUserValue rawUser
if err := json.Unmarshal(data, &rawUserValue); err != nil {
return err
}
2016-05-28 11:44:11 +00:00
2016-07-25 15:36:24 +00:00
u.Email = rawUserValue.EmailString
u.Level = UserLevel(rawUserValue.LevelByte)
return nil
}