diff options
author | René 'Necoro' Neumann <necoro@necoro.eu> | 2024-10-16 22:18:06 +0200 |
---|---|---|
committer | René 'Necoro' Neumann <necoro@necoro.eu> | 2024-10-16 22:18:06 +0200 |
commit | ca9d6a543335e998963ac4f680cf5c47e597602b (patch) | |
tree | caaeb8009bc64e800bd1b4cbee592954e3f5b8f9 /form/decode.go | |
parent | b20670125fede069a77e25d6414c3a5230e56f36 (diff) | |
download | gosten-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
@@ -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) } } |