Unnötige append() entfernt

This commit is contained in:
Jason Streifling 2023-11-01 11:56:44 +01:00
parent 817029c0dc
commit 224a99dec6

View File

@ -280,20 +280,12 @@ func (db *DB) GetQuestions(nums []string) ([]Question, error) {
// TODO: not scalable
questions := make([]Question, 0)
for rows.Next() {
q := Question{}
a1 := Answer{ID: 1}
a2 := Answer{ID: 2}
a3 := Answer{ID: 3}
a4 := Answer{ID: 4}
q := Question{Answers: make([]Answer, 4)}
if err := rows.Scan(&q.ID, &q.Text, &a1.Text, &a2.Text, &a3.Text, &a4.Text, &q.Correct); err != nil {
if err := rows.Scan(&q.ID, &q.Text, &q.Answers[0], &q.Answers[1], &q.Answers[2], &q.Answers[3], &q.Correct); err != nil {
return nil, fmt.Errorf("error: *DB.GetQuestions: rows.Scan(): %v", err)
}
q.Answers = append(q.Answers, a1)
q.Answers = append(q.Answers, a2)
q.Answers = append(q.Answers, a3)
q.Answers = append(q.Answers, a4)
questions = append(questions, q)
}