A web blog and personal homepage engine written in Go.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.0 KiB

package responses
import (
// TemplateFuncs available to all templates.
func TemplateFuncs(r *http.Request) template.FuncMap {
return template.FuncMap{
"CSRF": CSRF(r),
"FormValue": FormValue(r),
"TestFunction": TestFunction(r),
// CSRF returns the current CSRF token as an HTML hidden form field.
func CSRF(r *http.Request) func() template.HTML {
return func() template.HTML {
token, _ := r.Cookie(constants.CSRFCookieName)
return template.HTML(fmt.Sprintf(
`<input type="hidden" name="%s" value="%s">`,
// FormValue returns a form value (1st item only).
func FormValue(r *http.Request) func(string) string {
return func(key string) string {
return r.FormValue(key)
// TestFunction is a "hello world" template function.
func TestFunction(r *http.Request) func() template.HTML {
return func() template.HTML {
return template.HTML("TestFunction() called")