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.
v2ray-core/proxy/vmess/json/user.go

44 lines
919 B

package json
import (
"encoding/json"
"github.com/v2ray/v2ray-core/common/uuid"
"github.com/v2ray/v2ray-core/proxy/vmess"
)
// ConfigUser is an user account in VMess configuration.
type ConfigUser struct {
Id *vmess.ID
9 years ago
Email string
LevelValue vmess.UserLevel
}
func (u *ConfigUser) UnmarshalJSON(data []byte) error {
type rawUser struct {
IdString string `json:"id"`
EmailString string `json:"email"`
9 years ago
LevelInt int `json:"level"`
}
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 = vmess.NewID(id)
u.Email = rawUserValue.EmailString
u.LevelValue = vmess.UserLevel(rawUserValue.LevelInt)
return nil
}
func (u *ConfigUser) ID() *vmess.ID {
return u.Id
}
func (this *ConfigUser) Level() vmess.UserLevel {
9 years ago
return this.LevelValue
}