Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute all validators and get the collection of corresponding results #1233

Open
2 tasks done
maocatooo opened this issue Feb 18, 2024 · 1 comment
Open
2 tasks done

Comments

@maocatooo
Copy link

  • I have looked at the documentation here first?
  • I have looked at the examples provided that may showcase my question here?

Package version:

v10

Issue, Question or Enhancement:

Question
What should I do instead?

Code sample, to showcase or reproduce:

package main

import (
	"fmt"
	"github.com/go-playground/validator/v10"
)

type User struct {
	Email string `validate:"required,email,max=10"`
}

func main() {
	validate := validator.New()

	user := User{
		Email: "john11233exampleqwertyu",
	}

	err := validate.Struct(user)
	fmt.Println(len(err.(validator.ValidationErrors)) == 1 == true) // i need max error and email error
}
@deankarn
Copy link
Contributor

@maocatooo unfortunately there is no automated way to achieve what you're looking for as validator is designed to return only the first failed validation, per field, and changing the package to be able to support that would require it to be completely redesigned from the ground up.

There may be a way to achieve what your looking for using Struct Level validations, but would require you to run validations individually and them cobble the results together, almost the same as if doing it outside of the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants