func Index(w http.ResponseWriter, r *http.Request) { context := map[string]string{ "token": nosurf.Token(r), } if r.Method == "POST" { context["name"] = r.FormValue("name") } templ.Execute(w, context) }
func myFunc(w http.ResponseWriter, r *http.Request) { context := make(map[string]string) context["token"] = nosurf.Token(r) if r.Method == "POST" { context["name"] = r.FormValue("name") } templ.Execute(w, context) }
func myHandler(ctx *web.Context) { templateCtx := make(map[string]string) templateCtx["token"] = nosurf.Token(ctx.Request) if ctx.Request.Method == "POST" { templateCtx["name"] = ctx.Params["name"] } templ.Execute(ctx, templateCtx) }
func ShowSignupForm(c web.C, w http.ResponseWriter, r *http.Request) { templ.Execute(w, M{ "csrf_token": nosurf.Token(r), // Pass the CSRF token to the template }) }