init: Initial commit
This commit is contained in:
16
app/utils/http.go
Normal file
16
app/utils/http.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"github.com/go-playground/validator/v10"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
func ValidateRequest(c *fiber.Ctx, request interface{}) (*HTTPResponse, error) {
|
||||
if err := c.BodyParser(request); err != nil {
|
||||
return NewHTTPResponse(fiber.StatusBadRequest, &fiber.Map{"message": "Invalid request body"}, "", nil, nil), err
|
||||
}
|
||||
if err := validator.New().Struct(request); err != nil {
|
||||
return NewHTTPResponse(fiber.StatusBadRequest, &fiber.Map{"message": "Invalid request body"}, "", nil, nil), err
|
||||
}
|
||||
return NewHTTPResponse(fiber.StatusOK, nil, "", nil, nil), nil
|
||||
}
|
||||
Reference in New Issue
Block a user