Initial commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gookit/validate"
|
||||
"github.com/sujit-baniya/fiber-boilerplate/pkg/models"
|
||||
)
|
||||
|
||||
func ValidateApiRegisterPost(c *fiber.Ctx) error {
|
||||
var register models.RegisterForm
|
||||
if err := c.BodyParser(®ister); err != nil {
|
||||
return c.Status(401).JSON(fiber.Map{
|
||||
"error": true,
|
||||
"message": err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
v := validate.Struct(register)
|
||||
if !v.Validate() {
|
||||
return c.Status(401).JSON(fiber.Map{
|
||||
"error": true,
|
||||
"message": v.Errors,
|
||||
})
|
||||
}
|
||||
c.Locals("register", register)
|
||||
return c.Next()
|
||||
}
|
||||
Reference in New Issue
Block a user