GetByUsername returns the user with given username. It returns ErrUserNotExist when not found.
(ctx context.Context, username string)
| 744 | // GetByUsername returns the user with given username. It returns |
| 745 | // ErrUserNotExist when not found. |
| 746 | func (s *UsersStore) GetByUsername(ctx context.Context, username string) (*User, error) { |
| 747 | user := new(User) |
| 748 | err := s.db.WithContext(ctx).Where("lower_name = ?", strings.ToLower(username)).First(user).Error |
| 749 | if err != nil { |
| 750 | if errors.Is(err, gorm.ErrRecordNotFound) { |
| 751 | return nil, ErrUserNotExist{args: errutil.Args{"name": username}} |
| 752 | } |
| 753 | return nil, err |
| 754 | } |
| 755 | return user, nil |
| 756 | } |
| 757 | |
| 758 | // GetByKeyID returns the owner of given public key ID. It returns |
| 759 | // ErrUserNotExist when not found. |