golang-im聊天
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

user_repo.go 1.2 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package repo
  2. import (
  3. "gim/internal/business/domain/user/model"
  4. )
  5. type userRepo struct{}
  6. var UserRepo = new(userRepo)
  7. // Get 获取单个用户
  8. func (*userRepo) Get(userId int64) (*model.User, error) {
  9. user, err := UserCache.Get(userId)
  10. if err != nil {
  11. return nil, err
  12. }
  13. if user != nil {
  14. return user, nil
  15. }
  16. user, err = UserDao.Get(userId)
  17. if err != nil {
  18. return nil, err
  19. }
  20. if user != nil {
  21. err = UserCache.Set(*user)
  22. if err != nil {
  23. return nil, err
  24. }
  25. }
  26. return user, err
  27. }
  28. func (*userRepo) GetByPhoneNumber(phoneNumber string, masterId int64) (*model.User, error) {
  29. return UserDao.GetByPhoneNumber(phoneNumber, masterId)
  30. }
  31. // GetByIds 获取多个用户
  32. func (*userRepo) GetByIds(userIds []int64) ([]model.User, error) {
  33. return UserDao.GetByIds(userIds)
  34. }
  35. // Search 搜索用户
  36. func (*userRepo) Search(key string, masterId int64) ([]model.User, error) {
  37. return UserDao.Search(key, masterId)
  38. }
  39. // Save 保存用户
  40. func (*userRepo) Save(user *model.User) error {
  41. userId := user.Id
  42. err := UserDao.Save(user)
  43. if err != nil {
  44. return err
  45. }
  46. if userId != 0 {
  47. err = UserCache.Del(user.Id)
  48. if err != nil {
  49. return err
  50. }
  51. }
  52. return nil
  53. }