|
|
|
@ -182,6 +182,8 @@ func (v *Validate) RegisterCustomTypeFunc(fn CustomTypeFunc, types ...interface{ |
|
|
|
|
for _, t := range types { |
|
|
|
|
v.customFuncs[reflect.TypeOf(t)] = fn |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
v.hasCustomFuncs = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Struct validates a structs exposed fields, and automatically validates nested structs, unless otherwise specified.
|
|
|
|
@ -351,6 +353,10 @@ func (v *Validate) StructExcept(s interface{}, fields ...string) (err error) { |
|
|
|
|
// var i int
|
|
|
|
|
// validate.Var(i, "gt=1,lt=10")
|
|
|
|
|
//
|
|
|
|
|
// WARNING: a struct can be passed for validation eg. time.Time is a struct or if you have a custom type and have registered
|
|
|
|
|
// a custom type handler, so must allow it; however unforseen validations will occur if trying to validate a struct
|
|
|
|
|
// that is meant to be passed to 'validate.Struct'
|
|
|
|
|
//
|
|
|
|
|
// It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
|
|
|
|
|
// You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors.
|
|
|
|
|
// validate Array, Slice and maps fields which may contain more than one error
|
|
|
|
@ -399,6 +405,10 @@ func (v *Validate) Var(field interface{}, tag string) (err error) { |
|
|
|
|
// s2 := "abcd"
|
|
|
|
|
// validate.VarWithValue(s1, s2, "eqcsfield") // returns true
|
|
|
|
|
//
|
|
|
|
|
// WARNING: a struct can be passed for validation eg. time.Time is a struct or if you have a custom type and have registered
|
|
|
|
|
// a custom type handler, so must allow it; however unforseen validations will occur if trying to validate a struct
|
|
|
|
|
// that is meant to be passed to 'validate.Struct'
|
|
|
|
|
//
|
|
|
|
|
// It returns InvalidValidationError for bad values passed in and nil or ValidationErrors as error otherwise.
|
|
|
|
|
// You will need to assert the error if it's not nil eg. err.(validator.ValidationErrors) to access the array of errors.
|
|
|
|
|
// validate Array, Slice and maps fields which may contain more than one error
|
|
|
|
|