1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-06 10:20:44 -05:00
v2fly/proxy/vmess/config/json/user.go

43 lines
871 B
Go
Raw Normal View History

2015-10-16 06:03:22 -04:00
package json
import (
"encoding/json"
"github.com/v2ray/v2ray-core/proxy/vmess/config"
)
// ConfigUser is an user account in VMess configuration.
type ConfigUser struct {
2015-10-31 09:08:13 -04:00
Id *config.ID
Email string
LevelValue config.UserLevel
2015-10-16 06:03:22 -04:00
}
func (u *ConfigUser) UnmarshalJSON(data []byte) error {
type rawUser struct {
IdString string `json:"id"`
EmailString string `json:"email"`
2015-10-31 09:08:13 -04:00
LevelInt int `json:"level"`
2015-10-16 06:03:22 -04:00
}
var rawUserValue rawUser
if err := json.Unmarshal(data, &rawUserValue); err != nil {
return err
}
id, err := config.NewID(rawUserValue.IdString)
if err != nil {
return err
}
u.Id = id
u.Email = rawUserValue.EmailString
2015-10-31 09:08:13 -04:00
u.LevelValue = config.UserLevel(rawUserValue.LevelInt)
2015-10-16 06:03:22 -04:00
return nil
}
func (u *ConfigUser) ID() *config.ID {
return u.Id
}
2015-10-30 19:38:31 -04:00
func (this *ConfigUser) Level() config.UserLevel {
2015-10-31 09:08:13 -04:00
return this.LevelValue
}