asaskevich / govalidator

[Go] Package of validators and sanitizers for strings, numerics, slices and structs
MIT License
6.01k stars 556 forks source link

govalidator.ValidateStruct() #353

Open lb151 opened 4 years ago

lb151 commented 4 years ago

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

ygj6 commented 3 years ago

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
}
sergeyglazyrindev commented 2 years ago

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.