Messaging/pkg/internal/http/exts/utils.go

23 lines
529 B
Go
Raw Normal View History

package exts
2024-03-26 15:05:13 +00:00
import (
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
)
var validation = validator.New(validator.WithRequiredStructEnabled())
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
}
2024-08-23 11:32:24 +00:00
func ValidateStruct(in any) error {
return validation.Struct(in)
}