Base Project
This commit is contained in:
24
pkg/helper/validator.go
Normal file
24
pkg/helper/validator.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package helper
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"wm-backend/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
func IsShouldBindJSON(c *gin.Context, obj any) bool {
|
||||
if err := c.ShouldBindJSON(obj); err != nil {
|
||||
response.BadRequestError(c, http.StatusBadRequest, err.Error())
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
var validate = validator.New()
|
||||
|
||||
func IsEmail(input string) bool {
|
||||
err := validate.Var(input, "email")
|
||||
return err == nil
|
||||
}
|
||||
Reference in New Issue
Block a user