user.go 756 B

12345678910111213141516171819202122232425262728293031323334353637
  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. }
  18. func (u *User) ToMemoryUser() (*MemoryUser, error) {
  19. account, err := u.GetTypedAccount()
  20. if err != nil {
  21. return nil, err
  22. }
  23. return &MemoryUser{
  24. Account: account,
  25. Email: u.Email,
  26. Level: u.Level,
  27. }, nil
  28. }
  29. type MemoryUser struct {
  30. Account Account
  31. Email string
  32. Level uint32
  33. }