summaryrefslogtreecommitdiff
path: root/form/decode.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-16 22:18:06 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-16 22:18:06 +0200
commitca9d6a543335e998963ac4f680cf5c47e597602b (patch)
treecaaeb8009bc64e800bd1b4cbee592954e3f5b8f9 /form/decode.go
parentb20670125fede069a77e25d6414c3a5230e56f36 (diff)
downloadgosten-ca9d6a543335e998963ac4f680cf5c47e597602b.tar.gz
gosten-ca9d6a543335e998963ac4f680cf5c47e597602b.tar.bz2
gosten-ca9d6a543335e998963ac4f680cf5c47e597602b.zip
Inline form package
Diffstat (limited to '')
-rw-r--r--form/decode.go (renamed from form.go)21
1 files changed, 4 insertions, 17 deletions
diff --git a/form.go b/form/decode.go
index db0d097..7ebdfc2 100644
--- a/form.go
+++ b/form/decode.go
@@ -1,7 +1,7 @@
-package main
+package form
import (
- "fmt"
+ "gosten/csrf"
"log"
"net/http"
@@ -15,20 +15,7 @@ func init() {
schemaDecoder.IgnoreUnknownKeys(true)
}
-type fieldError struct {
- Field string
- Issue string
-}
-
-func (fe fieldError) Error() string {
- return fmt.Sprintf("%s: %v", fe.Field, fe.Issue)
-}
-
-func (fe fieldError) FieldError() (field, err string) {
- return fe.Field, fe.Issue
-}
-
-func parseForm[T any](r *http.Request, data *T) {
+func Parse[T any](r *http.Request, data *T) {
if err := r.ParseForm(); err != nil {
log.Panic("Parsing form: ", err)
}
@@ -36,7 +23,7 @@ func parseForm[T any](r *http.Request, data *T) {
log.Panic("Decoding form: ", err)
}
- if withCsrf, ok := any(data).(WithCsrf); ok {
+ if withCsrf, ok := any(data).(csrf.Enabled); ok {
withCsrf.SetCsrfField(r)
}
}