28 lines
591 B
Go
28 lines
591 B
Go
|
package responses
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"html/template"
|
||
|
"net/http"
|
||
|
|
||
|
"git.kirsle.net/apps/gophertype/pkg/constants"
|
||
|
)
|
||
|
|
||
|
// TemplateFuncs available to all templates.
|
||
|
func TemplateFuncs(r *http.Request) template.FuncMap {
|
||
|
return template.FuncMap{
|
||
|
"CSRF": func() template.HTML {
|
||
|
fmt.Println("CSRF() func called")
|
||
|
token, _ := r.Cookie(constants.CSRFCookieName)
|
||
|
return template.HTML(fmt.Sprintf(
|
||
|
`<input type="hidden" name="%s" value="%s">`,
|
||
|
constants.CSRFFormName,
|
||
|
token.Value,
|
||
|
))
|
||
|
},
|
||
|
"TestFunction": func() template.HTML {
|
||
|
return template.HTML("Testing")
|
||
|
},
|
||
|
}
|
||
|
}
|