Exemple #1
0
func Poll(w http.ResponseWriter, r *http.Request) {
	sess, err := us.MakeSession(r)
	poll, err := findPoll(r)

	if err != nil {
		http.Error(w, "Error: "+err.Error(), 500)
		return
	}

	locals := sess.Locals()
	locals["Poll"] = poll

	err = template.RenderTemplate(w, "poll.tmpl", locals)

	if err != nil {
		panic(err)
	}

	/*w.Header().Set("Content-Type", "text/html")
	w.Write([]byte(fmt.Sprintf("%v", poll.Collated())))
	fmt.Fprintf(w, `<form method="post" action="%s">
	<input type="text" name="answer">
	<input type="submit" name="submit">
	</form>`, r.URL.Path)*/
}
Exemple #2
0
func Home(w http.ResponseWriter, r *http.Request) {
	sess, err := us.MakeSession(r)

	if err != nil {
		http.Error(w, err.Error(), 500)
		return
	}

	sess.Save(w, r)

	err = template.RenderTemplate(w, "index.tmpl", sess.Locals())

	if err != nil {
		panic(err)
	}
}