@@ -303,7 +303,7 @@ func (v *Validate) traverseField(topStruct reflect.Value, currentStruct reflect.
303303
304304 if kind == reflect .Struct {
305305
306- // required passed validationa above so stop here
306+ // required passed validation above so stop here
307307 // if only validating the structs existance.
308308 if strings .Contains (tag , structOnlyTag ) {
309309 return
@@ -404,42 +404,31 @@ func (v *Validate) traverseField(topStruct reflect.Value, currentStruct reflect.
404404func (v * Validate ) traverseSlice (topStruct reflect.Value , currentStruct reflect.Value , current reflect.Value , errPrefix string , errs ValidationErrors , tag string , name string ) {
405405
406406 for i := 0 ; i < current .Len (); i ++ {
407-
408- idxField := current .Index (i )
409-
410- if idxField .Kind () == reflect .Ptr && ! idxField .IsNil () {
411- idxField = idxField .Elem ()
412- }
413-
414- v .traverseField (topStruct , currentStruct , idxField , errPrefix , errs , false , tag , fmt .Sprintf (arrayIndexFieldName , name , i ))
407+ v .traverseField (topStruct , currentStruct , current .Index (i ), errPrefix , errs , false , tag , fmt .Sprintf (arrayIndexFieldName , name , i ))
415408 }
416409}
417410
418411// traverseMap traverses a map's elements and passes them to traverseField for validation
419412func (v * Validate ) traverseMap (topStruct reflect.Value , currentStruct reflect.Value , current reflect.Value , errPrefix string , errs ValidationErrors , tag string , name string ) {
420413
421414 for _ , key := range current .MapKeys () {
422-
423- idxField := current .MapIndex (key )
424-
425- if idxField .Kind () == reflect .Ptr && ! idxField .IsNil () {
426- idxField = idxField .Elem ()
427- }
428-
429- v .traverseField (topStruct , currentStruct , idxField , errPrefix , errs , false , tag , fmt .Sprintf (mapIndexFieldName , name , key .Interface ()))
415+ v .traverseField (topStruct , currentStruct , current .MapIndex (key ), errPrefix , errs , false , tag , fmt .Sprintf (mapIndexFieldName , name , key .Interface ()))
430416 }
431417}
432418
433419// validateField validates a field based on the provided tag's key and param values and returns true if there is an error or false if all ok
434420func (v * Validate ) validateField (topStruct reflect.Value , currentStruct reflect.Value , current reflect.Value , currentType reflect.Type , currentKind reflect.Kind , errPrefix string , errs ValidationErrors , cTag * tagCache , name string ) bool {
435421
422+ var valFunc Func
423+ var ok bool
424+
436425 if cTag .isOrVal {
437426
438427 errTag := ""
439428
440429 for _ , val := range cTag .tagVals {
441430
442- valFunc , ok : = v .config .ValidationFuncs [val [0 ]]
431+ valFunc , ok = v .config .ValidationFuncs [val [0 ]]
443432 if ! ok {
444433 panic (strings .TrimSpace (fmt .Sprintf (undefinedValidation , name )))
445434 }
@@ -462,7 +451,7 @@ func (v *Validate) validateField(topStruct reflect.Value, currentStruct reflect.
462451 return true
463452 }
464453
465- valFunc , ok : = v .config .ValidationFuncs [cTag .tagVals [0 ][0 ]]
454+ valFunc , ok = v .config .ValidationFuncs [cTag .tagVals [0 ][0 ]]
466455 if ! ok {
467456 panic (strings .TrimSpace (fmt .Sprintf (undefinedValidation , name )))
468457 }
0 commit comments