The programable validator.
Existing validator is not fully flexible. We want to customize error object generation. We want to modify value instead of raise error when validation failed. We want it.
see usage
v := golidator.NewValidator()
err := v.Validate(obj)
v := golidator.NewValidator()
v.SetValidationFunc("req", func(t *validator.Target, param string) error {
val := t.FieldValue
if str := val.String(); str == "" {
return fmt.Errorf("unexpected value: %s", str)
}
return nil
})
v := &golidator.Validator{}
v.SetTag("validate")
v.SetValidationFunc("req", validator.ReqFactory(&validator.ReqErrorOption{
ReqError: func(f reflect.StructField, actual interface{}) error {
return fmt.Errorf("%s IS REQUIRED", f.Name)
},
}))