mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-09-09 05:26:39 -04:00
43 lines
858 B
Go
43 lines
858 B
Go
package json
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/v2ray/v2ray-core/proxy/vmess"
|
|
)
|
|
|
|
// ConfigUser is an user account in VMess configuration.
|
|
type ConfigUser struct {
|
|
Id *vmess.ID
|
|
Email string
|
|
LevelValue vmess.UserLevel
|
|
}
|
|
|
|
func (u *ConfigUser) UnmarshalJSON(data []byte) error {
|
|
type rawUser struct {
|
|
IdString string `json:"id"`
|
|
EmailString string `json:"email"`
|
|
LevelInt int `json:"level"`
|
|
}
|
|
var rawUserValue rawUser
|
|
if err := json.Unmarshal(data, &rawUserValue); err != nil {
|
|
return err
|
|
}
|
|
id, err := vmess.NewID(rawUserValue.IdString)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
u.Id = 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 {
|
|
return this.LevelValue
|
|
}
|