fix(binding): Expose validator engine used by the default Validator (#1277)
* fix(binding): Expose validator engine used by the default Validator
- Add func ValidatorEngine for returning the underlying validator engine used
in the default StructValidator implementation.
- Remove the function RegisterValidation from the StructValidator interface
which made it immpossible to use a StructValidator implementation without the
validator.v8 library.
- Update and rename test for registering validation
Test{RegisterValidation => ValidatorEngine}.
- Update readme and example for registering custom validation.
- Add example for registering struct level validation.
- Add documentation for the following binding funcs/types:
- Binding interface
- StructValidator interface
- Validator instance
- Binding implementations
- Default func
* fix(binding): Move validator engine getter inside interface
* docs: rm date cmd from custom validation demo
This commit is contained in:
@@ -28,9 +28,13 @@ func (v *defaultValidator) ValidateStruct(obj interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *defaultValidator) RegisterValidation(key string, fn validator.Func) error {
|
||||
// Engine returns the underlying validator engine which powers the default
|
||||
// Validator instance. This is useful if you want to register custom validations
|
||||
// or struct level validations. See validator GoDoc for more info -
|
||||
// https://godoc.org/gopkg.in/go-playground/validator.v8
|
||||
func (v *defaultValidator) Engine() interface{} {
|
||||
v.lazyinit()
|
||||
return v.validate.RegisterValidation(key, fn)
|
||||
return v.validate
|
||||
}
|
||||
|
||||
func (v *defaultValidator) lazyinit() {
|
||||
|
||||
Reference in New Issue
Block a user