user.go 808 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package protocol
  2. import "time"
  3. func (u *User) GetTypedAccount() (Account, error) {
  4. if u.GetAccount() == nil {
  5. return nil, newError("Account missing").AtWarning()
  6. }
  7. rawAccount, err := u.Account.GetInstance()
  8. if err != nil {
  9. return nil, err
  10. }
  11. if asAccount, ok := rawAccount.(AsAccount); ok {
  12. return asAccount.AsAccount()
  13. }
  14. if account, ok := rawAccount.(Account); ok {
  15. return account, nil
  16. }
  17. return nil, newError("Unknown account type: ", u.Account.Type)
  18. }
  19. func (u *User) GetSettings() UserSettings {
  20. settings := UserSettings{}
  21. switch u.Level {
  22. case 0:
  23. settings.PayloadTimeout = time.Second * 30
  24. case 1:
  25. settings.PayloadTimeout = time.Minute * 2
  26. default:
  27. settings.PayloadTimeout = time.Minute * 5
  28. }
  29. return settings
  30. }
  31. type UserSettings struct {
  32. PayloadTimeout time.Duration
  33. }