Add request data to template Execute function
This commit is contained in:
parent
da5eeb3f0f
commit
8bc58eedbe
@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Template interface {
|
type Template interface {
|
||||||
Execute(w http.ResponseWriter, data interface{})
|
Execute(w http.ResponseWriter, r *http.Request, data interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
func StaticController(templatePath ...string) http.HandlerFunc {
|
func StaticController(templatePath ...string) http.HandlerFunc {
|
||||||
@ -20,7 +20,7 @@ func StaticController(templatePath ...string) http.HandlerFunc {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) { tpl.Execute(w, nil) }
|
return func(w http.ResponseWriter, r *http.Request) { tpl.Execute(w, r, nil) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func FAQ(templatePath ...string) http.HandlerFunc {
|
func FAQ(templatePath ...string) http.HandlerFunc {
|
||||||
@ -47,6 +47,6 @@ func FAQ(templatePath ...string) http.HandlerFunc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
tpl.Execute(w, questions)
|
tpl.Execute(w, r, questions)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@ func (u Users) GetSignup(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
data.Email = r.FormValue("email")
|
data.Email = r.FormValue("email")
|
||||||
data.CSRFField = csrf.TemplateField(r)
|
data.CSRFField = csrf.TemplateField(r)
|
||||||
u.Templates.Signup.Execute(w, data)
|
u.Templates.Signup.Execute(w, r, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u Users) PostSignup(w http.ResponseWriter, r *http.Request) {
|
func (u Users) PostSignup(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -49,7 +49,7 @@ func (u Users) GetSignin(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
data.Email = r.FormValue("email")
|
data.Email = r.FormValue("email")
|
||||||
data.CSRFField = csrf.TemplateField(r)
|
data.CSRFField = csrf.TemplateField(r)
|
||||||
u.Templates.Signin.Execute(w, data)
|
u.Templates.Signin.Execute(w, r, data)
|
||||||
}
|
}
|
||||||
func (u Users) PostSignin(w http.ResponseWriter, r *http.Request) {
|
func (u Users) PostSignin(w http.ResponseWriter, r *http.Request) {
|
||||||
var data struct {
|
var data struct {
|
||||||
|
|||||||
@ -14,7 +14,7 @@ type Template struct {
|
|||||||
htmlTpl *template.Template
|
htmlTpl *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t Template) Execute(w http.ResponseWriter, data interface{}) {
|
func (t Template) Execute(w http.ResponseWriter, r *http.Request, data interface{}) {
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
w.Header().Set("Content-Type", "text/html; charset=utf8")
|
||||||
err := t.htmlTpl.Execute(w, data)
|
err := t.htmlTpl.Execute(w, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user