Commit b19956f
Changed files (1)
serverHandlers.go
@@ -39,13 +39,25 @@ func buildRecordArray(numQuestions int, categoryIndices []int) []Record {
catChosen = categoryIndices[rand.Intn(numCats)]
} else {
catChosen = rand.Intn(totalCats)
+ }
+ return recordArray, err
+}
+
+func parseBluePrint(blueprint string) ([]string, error) {
+ splits := strings.Split(blueprint, "-")
+ chosenCategories := make([]string, len(splits))
+ for i, key := range splits {
+ tempIndex, err := strconv.Atoi(strings.TrimSpace(key))
+ if err != nil {
+ return nil, fmt.Errorf("Error parsing numbers: %+v", err)
}
- record := getRecordForCategory(catChosen)
- if record.Answer != "" {
- recordArray = append(recordArray, record)
+ if tempIndex < len(categories) {
+ chosenCategories[i] = categories[tempIndex]
+ } else {
+ return nil, fmt.Errorf("Selected index too large for categories: %d", tempIndex)
}
}
- return recordArray
+ return chosenCategories, nil
}
// handleRequestForTest provides a JSON formatted test for the client