user.go 459 B

12345678910111213141516171819
  1. package protocol
  2. func (u *User) GetTypedAccount() (Account, error) {
  3. if u.GetAccount() == nil {
  4. return nil, newError("Account missing").AtWarning()
  5. }
  6. rawAccount, err := u.Account.GetInstance()
  7. if err != nil {
  8. return nil, err
  9. }
  10. if asAccount, ok := rawAccount.(AsAccount); ok {
  11. return asAccount.AsAccount()
  12. }
  13. if account, ok := rawAccount.(Account); ok {
  14. return account, nil
  15. }
  16. return nil, newError("Unknown account type: ", u.Account.Type)
  17. }