summaryrefslogtreecommitdiff
path: root/form/errors.go
diff options
context:
space:
mode:
authorRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-17 16:37:23 +0200
committerRené 'Necoro' Neumann <necoro@necoro.eu>2024-10-17 16:37:23 +0200
commitb2447bc967df37b31282a97e32c581954bb8bcc9 (patch)
tree39758d1121fae6dc1d27e8a45035690421900d6c /form/errors.go
parent789d21034e526a03d3e91d5d284a4888be938340 (diff)
downloadgosten-b2447bc967df37b31282a97e32c581954bb8bcc9.tar.gz
gosten-b2447bc967df37b31282a97e32c581954bb8bcc9.tar.bz2
gosten-b2447bc967df37b31282a97e32c581954bb8bcc9.zip
Move from html/template to templ
Diffstat (limited to 'form/errors.go')
-rw-r--r--form/errors.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/form/errors.go b/form/errors.go
new file mode 100644
index 0000000..52206c4
--- /dev/null
+++ b/form/errors.go
@@ -0,0 +1,30 @@
+package form
+
+import (
+ "errors"
+ "fmt"
+)
+
+type FieldError struct {
+ Field string
+ Issue string
+}
+
+func (fe FieldError) Error() string {
+ return fmt.Sprintf("%s: %v", fe.Field, fe.Issue)
+}
+
+// errors will build a map where each key is the field name, and each
+// value is a slice of strings representing errors with that field.
+func fieldErrors(errs []error) map[string][]string {
+ ret := make(map[string][]string)
+ for _, err := range errs {
+ var fe FieldError
+ if !errors.As(err, &fe) {
+ fmt.Println(err, "isnt field error")
+ continue
+ }
+ ret[fe.Field] = append(ret[fe.Field], fe.Issue)
+ }
+ return ret
+}