Returns validation error as single string
This commit is contained in:
parent
9b06e6a5cc
commit
971ce6e2a4
1 changed files with 9 additions and 5 deletions
|
|
@ -24,13 +24,17 @@ func ValidateModel[T ModelConstraint](s T) *fiber.Error {
|
|||
validate := validator.New()
|
||||
err := validate.Struct(s)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("%#v", err)
|
||||
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, err := range err.(validator.ValidationErrors) {
|
||||
err := fmt.Sprintf("Field %s is invalid, reason: %s", err.StructNamespace(), err.Tag())
|
||||
|
||||
errorMessages = append(errorMessages, err)
|
||||
}
|
||||
}
|
||||
|
||||
return fiber.NewError(fiber.StatusBadRequest, strings.Join(errorMessages, ". "))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue