From 870c9981f52ce9846d66960d0350c4014cc51a90 Mon Sep 17 00:00:00 2001 From: zytell3301 Date: Mon, 19 Apr 2021 02:57:30 +0430 Subject: [PATCH] Handle error when invalid data is supplied for diving --- validator_instance.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/validator_instance.go b/validator_instance.go index 6f244cd2..8e27707e 100644 --- a/validator_instance.go +++ b/validator_instance.go @@ -153,6 +153,8 @@ func (v Validate) ValidateMapCtx(ctx context.Context, data map[string]interface{ if len(err) > 0 { errs[field] = err } + } else if reflect.ValueOf(rule).Kind() == reflect.Map { + errs[field] = errors.New("The field: '" + field + "' is not a map to dive") } else { err := v.VarCtx(ctx, data[field], rule.(string)) if err != nil { @@ -165,7 +167,7 @@ func (v Validate) ValidateMapCtx(ctx context.Context, data map[string]interface{ // ValidateMap validates map data form a map of tags func (v *Validate) ValidateMap(data map[string]interface{}, rules map[string]interface{}) map[string]interface{} { - return v.ValidateMapCtx(context.Background(),data,rules) + return v.ValidateMapCtx(context.Background(), data, rules) } // RegisterTagNameFunc registers a function to get alternate names for StructFields.