v2ray-core/proxy/vmess/json/user.go

44 lines
919 B
Go
Raw Normal View History

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