1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-16 17:38:45 -05:00
v2fly/common/protocol/user.go

40 lines
893 B
Go
Raw Normal View History

package protocol
2015-10-16 06:03:22 -04:00
2017-08-24 16:56:31 -04:00
func (u *User) GetTypedAccount() (Account, error) {
if u.GetAccount() == nil {
return nil, newError("Account missing").AtWarning()
}
2016-10-16 08:22:21 -04:00
2017-08-24 16:56:31 -04:00
rawAccount, err := u.Account.GetInstance()
2016-09-17 18:41:21 -04:00
if err != nil {
return nil, err
}
2016-10-16 08:22:21 -04:00
if asAccount, ok := rawAccount.(AsAccount); ok {
return asAccount.AsAccount()
}
if account, ok := rawAccount.(Account); ok {
return account, nil
}
2017-08-24 16:56:31 -04:00
return nil, newError("Unknown account type: ", u.Account.Type)
2015-12-12 18:10:35 -05:00
}
2018-08-26 18:11:32 -04:00
func (u *User) ToMemoryUser() (*MemoryUser, error) {
account, err := u.GetTypedAccount()
if err != nil {
return nil, err
}
return &MemoryUser{
Account: account,
Email: u.Email,
Level: u.Level,
}, nil
}
2018-10-15 02:36:50 -04:00
// MemoryUser is a parsed form of User, to reduce number of parsing of Account proto.
2018-08-26 18:11:32 -04:00
type MemoryUser struct {
2018-10-15 02:36:50 -04:00
// Account is the parsed account of the protocol.
2018-08-26 18:11:32 -04:00
Account Account
Email string
Level uint32
}