diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2024-10-17 16:37:23 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2024-10-17 16:37:23 +0200 |
commit | b2447bc967df37b31282a97e32c581954bb8bcc9 (patch) | |
tree | 39758d1121fae6dc1d27e8a45035690421900d6c /csrf | |
parent | 789d21034e526a03d3e91d5d284a4888be938340 (diff) | |
download | gosten-b2447bc967df37b31282a97e32c581954bb8bcc9.tar.gz gosten-b2447bc967df37b31282a97e32c581954bb8bcc9.tar.bz2 gosten-b2447bc967df37b31282a97e32c581954bb8bcc9.zip |
Move from html/template to templ
Diffstat (limited to '')
-rw-r--r-- | csrf/csrf.go | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/csrf/csrf.go b/csrf/csrf.go index 18fdb81..fd73c0d 100644 --- a/csrf/csrf.go +++ b/csrf/csrf.go @@ -4,6 +4,7 @@ import ( "html/template" "net/http" + "github.com/a-h/templ" "github.com/gorilla/csrf" "github.com/gorilla/securecookie" ) @@ -12,18 +13,22 @@ func Handler() func(http.Handler) http.Handler { return csrf.Protect( securecookie.GenerateRandomKey(32), csrf.SameSite(csrf.SameSiteStrictMode), - csrf.FieldName("csrf.csrffield"), // should match the structure in `Csrf` + csrf.FieldName("csrffield.field"), // should match the structure in `Csrf` ) } -// Csrf handles the CSRF data for a form. +// CsrfField handles the CSRF data for a form. // Include it verbatim and then use `{{.CsrfField}}` in templates. -type Csrf struct { - CsrfField template.HTML `form:"-" schema:"-"` +type CsrfField struct { + field template.HTML `form:"-" schema:"-"` } -func (c *Csrf) SetCsrfField(r *http.Request) { - c.CsrfField = csrf.TemplateField(r) +func (c *CsrfField) SetCsrfField(r *http.Request) { + c.field = csrf.TemplateField(r) +} + +func (c *CsrfField) Csrf() templ.Component { + return templ.Raw(c.field) } type Enabled interface { |