Now we have a working version without any JS. Way easier to do because javascript form submit blows hot wads.
This commit is contained in:
parent
3fd8169d83
commit
504433502a
3 changed files with 33 additions and 21 deletions
|
@ -2,6 +2,7 @@ package common
|
|||
|
||||
import (
|
||||
"log"
|
||||
"reflect"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
@ -40,3 +41,26 @@ func ReceivePost[T any](c *fiber.Ctx) (*T, error) {
|
|||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func ReflectOnPost(typeOf reflect.Type, c *fiber.Ctx) (reflect.Value, error) {
|
||||
var result_val reflect.Value
|
||||
|
||||
result_val = reflect.New(typeOf)
|
||||
result := result_val.Interface()
|
||||
|
||||
if err := c.BodyParser(result); err != nil {
|
||||
log.Println(err);
|
||||
return result_val, err
|
||||
}
|
||||
|
||||
var validate *validator.Validate
|
||||
validate = validator.New(validator.WithRequiredStructEnabled())
|
||||
|
||||
if err := validate.Struct(result); err != nil {
|
||||
validationErrors := err.(validator.ValidationErrors)
|
||||
log.Println(validationErrors)
|
||||
return result_val, err
|
||||
}
|
||||
|
||||
return result_val, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue