1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-05 00:47:51 -05:00
v2fly/proxy/vmess/json/user.go

43 lines
858 B
Go
Raw Normal View History

2015-10-16 06:03:22 -04:00
package json
import (
"encoding/json"
2015-12-07 14:32:38 -05:00
"github.com/v2ray/v2ray-core/proxy/vmess"
2015-10-16 06:03:22 -04:00
)
// ConfigUser is an user account in VMess configuration.
type ConfigUser struct {
2015-12-07 14:32:38 -05:00
Id *vmess.ID
2015-10-31 09:08:13 -04:00
Email string
2015-12-07 14:32:38 -05:00
LevelValue vmess.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
}
2015-12-07 14:32:38 -05:00
id, err := vmess.NewID(rawUserValue.IdString)
2015-10-16 06:03:22 -04:00
if err != nil {
return err
}
u.Id = id
u.Email = rawUserValue.EmailString
2015-12-07 14:32:38 -05:00
u.LevelValue = vmess.UserLevel(rawUserValue.LevelInt)
2015-10-16 06:03:22 -04:00
return nil
}
2015-12-07 14:32:38 -05:00
func (u *ConfigUser) ID() *vmess.ID {
2015-10-16 06:03:22 -04:00
return u.Id
}
2015-10-30 19:38:31 -04:00
2015-12-07 14:32:38 -05:00
func (this *ConfigUser) Level() vmess.UserLevel {
2015-10-31 09:08:13 -04:00
return this.LevelValue
}