示例#1
0
文件: polls.go 项目: atamis/wt3
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)*/
}
示例#2
0
文件: home.go 项目: atamis/wt3
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)
	}
}