Пример #1
0
func PrepareHandler(w http.ResponseWriter, r *http.Request) {
	playData := game.NewPlayData()

	r.ParseForm()
	if val, ok := r.Form["words[]"]; ok {
		for _, rawWord := range val {
			defaultWord := german.Default{}

			err := json.Unmarshal([]byte(rawWord), &defaultWord)
			if err != nil {
				log.Println(err)
				continue
			}

			playData.Question = defaultWord.GetEnglish()
			playData.DataStore = defaultWord
		}
	}

	outputBytes, err := json.Marshal(playData)
	if err != nil {
		log.Println(err)
		w.WriteHeader(http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write(outputBytes)
}