Esempio n. 1
0
func handler(w http.ResponseWriter, r *http.Request) {
	switch r.Method {
	case "GET":
		templates.ExecuteTemplate(w, "form.html", "")
	case "POST":
		if m, err := formInts(r, "pc", "lp"); err != nil {
			log.Println(err)
		} else {
			exp := []sentinels.ExpansionType{}
			for i, v := range expansions {
				if r.FormValue(v) == "on" {
					exp = append(exp, sentinels.ExpansionType(i))
				}
			}
			r := &result{}
			if len(exp) == 0 {
				r.Msg = "No card set selected."
			} else {
				r.PC = m["pc"]
				r.LP = m["lp"]
				r.Nump = fmt.Sprintf("%d heroes", m["pc"])
				var err error
				if r.Setup, r.Iterations, err = sentinels.FindSetup(r.PC, r.LP, 10, exp); err != nil {
					r.Msg = err.Error()
				}
			}
			templates.ExecuteTemplate(w, "result.html", r)
		}
	default:
		log.Printf("Unhandled method: %s", r.Method)
	}
}