mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-20 15:05:09 +00:00
massive refactoring against json config parsing
This commit is contained in:
1 parent
f87ab4713c
commit
e5fa96f814
51 files changed
+424
-586
No files matched your search
@@ -0,0 +1,42 @@
|
||||
// +build json
|
||||
|
||||
package vmess
|
||||
|
||||
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"`
|
||||
LevelInt int `json:"level"`
|
||||
AlterIdCount int `json:"alterId"`
|
||||
}
|
||||
var rawUserValue rawUser
|
||||
if err := json.Unmarshal(data, &rawUserValue); err != nil {
|
||||
return err
|
||||
}
|
||||
id, err := uuid.ParseString(rawUserValue.IdString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
u.ID = NewID(id)
|
||||
//u.Email = rawUserValue.EmailString
|
||||
u.Level = UserLevel(rawUserValue.LevelInt)
|
||||
|
||||
if rawUserValue.AlterIdCount > 0 {
|
||||
prevId := u.ID.UUID()
|
||||
// TODO: check duplicate
|
||||
u.AlterIDs = make([]*ID, rawUserValue.AlterIdCount)
|
||||
for idx, _ := range u.AlterIDs {
|
||||
newid := prevId.Next()
|
||||
u.AlterIDs[idx] = NewID(newid)
|
||||
prevId = newid
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user