Skip to content

Commit

Permalink
Enabled nested pointer handling in slices/maps
Browse files Browse the repository at this point in the history
  • Loading branch information
BoBch27 committed Dec 2, 2024
1 parent c891121 commit 504428f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ func (v *validator) processMapValue(
for iter.Next() {
key := iter.Key()
val := iter.Value()
kind := val.Kind()

if kind == reflect.Pointer {
val = val.Elem()
kind = val.Kind()
}

newFs := &fieldScope{
strct: fs.strct,
Expand All @@ -469,7 +475,7 @@ func (v *validator) processMapValue(
path: fmt.Sprintf("%s.%v", fs.path, key.Interface()),
structPath: fmt.Sprintf("%s.%v", fs.structPath, key.Interface()),
value: val,
kind: val.Kind(),
kind: kind,
typ: val.Type(),
}

Expand All @@ -494,6 +500,12 @@ func (v *validator) processSliceValue(

for i := 0; i < fs.value.Len(); i++ {
val := fs.value.Index(i)
kind := val.Kind()

if kind == reflect.Pointer {
val = val.Elem()
kind = val.Kind()
}

newFs := &fieldScope{
strct: fs.strct,
Expand All @@ -502,7 +514,7 @@ func (v *validator) processSliceValue(
path: fmt.Sprintf("%s[%d]", fs.path, i),
structPath: fmt.Sprintf("%s[%d]", fs.structPath, i),
value: val,
kind: val.Kind(),
kind: kind,
typ: val.Type(),
}

Expand Down

0 comments on commit 504428f

Please sign in to comment.