govalidator
govalidator copied to clipboard
Wrong error msg when required field is not set
When govalidator.SetFieldsRequiredByDefault
is enabled, the error message for an unset field is misleading.
It reports "validation missing" for any validation except valid:"-"
:
All fields are required to at least have one validation defined;
Full Test Case
package main
import (
"log"
"github.com/asaskevich/govalidator"
)
type S struct {
Url string `valid:"url"`
}
func main() {
govalidator.SetFieldsRequiredByDefault(true)
s := &S{}
_, err := govalidator.ValidateStruct(s)
if err != nil {
log.Print(err)
}
}
I think this is expected behavior, unless I'm not understanding the documentation correctly. See the main README. Search for Activate behavior to require all fields have a validation tag by default. It explains what you are seeing and yes "-" would mark a specific field except from the check.
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.