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 }