asaskevich / govalidator

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

Validate only when field is non-nil? #366

Open fushar opened 4 years ago

fushar commented 4 years ago

Suppose that I have this struct:

type PersonUpdateRequest struct {
    Name *string `json:"name"`
    Age  *int    `json:"age"`
}

This represent a request body of a REST endpoint to PATCH a person entity.

I want to validate name that, if it is non-nil, it must not be empty string. Similarly for age, if it is non-nil, it must not be nonzero.

Is this possible to do using this library?

toby3d commented 4 years ago

As workaround for #359 use go mod edit -replace "github.com/asaskevich/govalidator=github.com/asaskevich/govalidator@v0.0.0-20200108184127-ac8f5a34c3f7" for revert latest broken patch.

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.