govalidator icon indicating copy to clipboard operation
govalidator copied to clipboard

govalidator.ValidateStruct()

Open lb151 opened this issue 4 years ago • 2 comments

The result of the structure verification is returned and a single error message is returned,Validation stops at one error and returns an error instead of validating all

lb151 avatar Oct 16 '19 01:10 lb151

I've written an example to test it. There are three errors in Addresses, but only one error is given. The code is as follows:

func TestIssue353(t *testing.T) {
	type Address struct {
		CountryCode string `json:"country_code11" valid:"ISO3166Alpha3"`
	}

	type Details struct {
		Email string `json:"email" valid:"email"`
	}

	type Person struct {
		Details   Details   `json:"details"`
		Addresses []Address `json:"addresses"`
	}

	p := Person{
		Details: Details{
			Email: "gogopher@example-com", //gogopher@example-com

		},
		Addresses: []Address{
			{CountryCode: "GBP"},
			{CountryCode: "AUS"},
			{CountryCode: "CUS"},
			{CountryCode: "DUS"},
		},
	}
	_, err := ValidateStruct(p)

	fmt.Println(strings.ReplaceAll(err.Error(), ";", "\n"))
	//output:
	//Addresses.0.addresses: GBP does not validate as ISO3166Alpha3
	//Details.email: gogopher@example-com does not validate as email
}

ygj6 avatar Sep 12 '20 02:09 ygj6

Hello guys! I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back Link to my repo: create issue there and we'll discuss it.

sergeyglazyrindev avatar Oct 17 '21 21:10 sergeyglazyrindev