1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-07-03 20:45:23 +00:00
v2fly/common/protocol/user.go

20 lines
459 B
Go
Raw Normal View History

package protocol
2015-10-16 10:03:22 +00:00
2017-08-24 20:56:31 +00:00
func (u *User) GetTypedAccount() (Account, error) {
if u.GetAccount() == nil {
return nil, newError("Account missing").AtWarning()
}
2016-10-16 12:22:21 +00:00
2017-08-24 20:56:31 +00:00
rawAccount, err := u.Account.GetInstance()
2016-09-17 22:41:21 +00:00
if err != nil {
return nil, err
}
2016-10-16 12:22:21 +00:00
if asAccount, ok := rawAccount.(AsAccount); ok {
return asAccount.AsAccount()
}
if account, ok := rawAccount.(Account); ok {
return account, nil
}
2017-08-24 20:56:31 +00:00
return nil, newError("Unknown account type: ", u.Account.Type)
2015-12-12 23:10:35 +00:00
}