summaryrefslogtreecommitdiff
path: root/form/decode.go
diff options
context:
space:
mode:
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)
}
}