@@ -33,6 +33,7 @@ const (
3333 mapErrMsg = "Field validation for \" %s\" failed on key \" %v\" with error(s): %s"
3434 structErrMsg = "Struct:%s\n "
3535 diveTag = "dive"
36+ existsTag = "exists"
3637 arrayIndexFieldName = "%s[%d]"
3738 mapIndexFieldName = "%s[%v]"
3839)
@@ -722,7 +723,22 @@ func (v *Validate) fieldWithNameAndValue(val interface{}, current interface{}, f
722723
723724 for _ , val := range cTag .keyVals {
724725
726+ // if (idxField.Kind() == reflect.Ptr || idxField.Kind() == reflect.Interface) && idxField.IsNil() {
727+ // if val[0] == existsTag {
728+ // if (cField.kind == reflect.Ptr || cField.kind == reflect.Interface) && valueField.IsNil() {
729+ // fieldErr = &FieldError{
730+ // Field: name,
731+ // Tag: val[0],
732+ // Value: f,
733+ // Param: val[1],
734+ // }
735+ // err = errors.New(fieldErr.Tag)
736+ // }
737+
738+ // } else {
739+
725740 fieldErr , err = v .fieldWithNameAndSingleTag (val , current , f , val [0 ], val [1 ], name )
741+ // }
726742
727743 if err == nil {
728744 return nil
@@ -740,6 +756,18 @@ func (v *Validate) fieldWithNameAndValue(val interface{}, current interface{}, f
740756 return fieldErr
741757 }
742758
759+ if cTag .keyVals [0 ][0 ] == existsTag {
760+ if (cField .kind == reflect .Ptr || cField .kind == reflect .Interface ) && valueField .IsNil () {
761+ return & FieldError {
762+ Field : name ,
763+ Tag : cTag .keyVals [0 ][0 ],
764+ Value : f ,
765+ Param : cTag .keyVals [0 ][1 ],
766+ }
767+ }
768+ continue
769+ }
770+
743771 if fieldErr , err = v .fieldWithNameAndSingleTag (val , current , f , cTag .keyVals [0 ][0 ], cTag .keyVals [0 ][1 ], name ); err != nil {
744772
745773 fieldErr .Kind = cField .kind
@@ -981,6 +1009,10 @@ func (v *Validate) fieldWithNameAndSingleTag(val interface{}, current interface{
9811009 return nil , nil
9821010 }
9831011
1012+ // if key == existsTag {
1013+ // continue
1014+ // }
1015+
9841016 valFunc , ok := v .validationFuncs [key ]
9851017 if ! ok {
9861018 panic (fmt .Sprintf ("Undefined validation function on field %s" , name ))
0 commit comments