Fixed null user being returned if id not in database
This commit is contained in:
@@ -56,11 +56,12 @@ func fetchUserData(
|
|||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scan the next row into the provided user pointer. Calls rows.Next() and
|
// Calls rows.Next() and scans the row into the provided user pointer.
|
||||||
// assumes only row in the result. Providing a rows object with more than 1
|
// Will error if no row available
|
||||||
// row may result in undefined behaviour.
|
|
||||||
func scanUserRow(user *User, rows *sql.Rows) error {
|
func scanUserRow(user *User, rows *sql.Rows) error {
|
||||||
for rows.Next() {
|
if !rows.Next() {
|
||||||
|
return errors.New("User not found")
|
||||||
|
}
|
||||||
err := rows.Scan(
|
err := rows.Scan(
|
||||||
&user.ID,
|
&user.ID,
|
||||||
&user.Username,
|
&user.Username,
|
||||||
@@ -71,7 +72,6 @@ func scanUserRow(user *User, rows *sql.Rows) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "rows.Scan")
|
return errors.Wrap(err, "rows.Scan")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user