walk: deal with array

This commit is contained in:
Muyao CHEN 2024-09-20 20:37:54 +02:00
parent 799d730d14
commit f64d75ca45
2 changed files with 9 additions and 1 deletions

View File

@ -16,7 +16,7 @@ func Walk(x interface{}, fn func(string)) {
case reflect.Struct: case reflect.Struct:
numberOfValues = val.NumField() numberOfValues = val.NumField()
getField = val.Field getField = val.Field
case reflect.Slice: case reflect.Slice, reflect.Array:
numberOfValues = val.Len() numberOfValues = val.Len()
getField = val.Index getField = val.Index
} }

View File

@ -62,6 +62,14 @@ func TestWalk(t *testing.T) {
}, },
[]string{"London", "Paris"}, []string{"London", "Paris"},
}, },
{
"arrays",
[2]Profile{
{29, "London"},
{33, "Paris"},
},
[]string{"London", "Paris"},
},
} }
for _, test := range cases { for _, test := range cases {