2024-01-26 17:11:32 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
|
|
)
|
|
|
|
|
2024-01-31 13:16:54 +00:00
|
|
|
var validation = validator.New(validator.WithRequiredStructEnabled())
|
2024-01-26 17:11:32 +00:00
|
|
|
|
|
|
|
func BindAndValidate(c *fiber.Ctx, out any) error {
|
|
|
|
if err := c.BodyParser(out); err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
|
|
|
} else if err := validation.Struct(out); err != nil {
|
|
|
|
return fiber.NewError(fiber.StatusBadRequest, err.Error())
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|