mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
621 B
30 lines
621 B
9 years ago
|
// +build json
|
||
|
|
||
9 years ago
|
package protocol
|
||
9 years ago
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
|
||
|
"github.com/v2ray/v2ray-core/common/uuid"
|
||
|
)
|
||
|
|
||
|
func (u *User) UnmarshalJSON(data []byte) error {
|
||
|
type rawUser struct {
|
||
|
IdString string `json:"id"`
|
||
|
EmailString string `json:"email"`
|
||
9 years ago
|
LevelByte byte `json:"level"`
|
||
9 years ago
|
AlterIdCount uint16 `json:"alterId"`
|
||
9 years ago
|
}
|
||
|
var rawUserValue rawUser
|
||
|
if err := json.Unmarshal(data, &rawUserValue); err != nil {
|
||
|
return err
|
||
|
}
|
||
|
id, err := uuid.ParseString(rawUserValue.IdString)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
9 years ago
|
*u = *NewUser(NewID(id), UserLevel(rawUserValue.LevelByte), rawUserValue.AlterIdCount)
|
||
9 years ago
|
|
||
|
return nil
|
||
|
}
|