From ee9cf057964c52f353dfa381ae1c2cebe98c30aa Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sun, 28 Jan 2018 17:40:05 +0100 Subject: [PATCH] Handle pointer validation --- validation/validation.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/validation/validation.go b/validation/validation.go index 0d89be30..f2d94687 100644 --- a/validation/validation.go +++ b/validation/validation.go @@ -245,7 +245,17 @@ func (v *Validation) ZipCode(obj interface{}, key string) *Result { } func (v *Validation) apply(chk Validator, obj interface{}) *Result { - if chk.IsSatisfied(obj) { + if reflect.TypeOf(obj).Kind() == reflect.Ptr { + if reflect.ValueOf(obj).IsNil() { + if "Required" != chk.GetKey() { + return &Result{Ok: true} + } + } else { + if chk.IsSatisfied(reflect.ValueOf(obj).Elem().Interface()) { + return &Result{Ok: true} + } + } + } else if chk.IsSatisfied(obj) { return &Result{Ok: true} }