walk: deal with maps

This commit is contained in:
Muyao CHEN 2024-09-20 20:41:50 +02:00
parent f64d75ca45
commit 61a0d0ff03
2 changed files with 12 additions and 0 deletions

View File

@ -19,6 +19,10 @@ func Walk(x interface{}, fn func(string)) {
case reflect.Slice, reflect.Array:
numberOfValues = val.Len()
getField = val.Index
case reflect.Map:
for _, key := range val.MapKeys() {
Walk(val.MapIndex(key).Interface(), fn)
}
}
for i := 0; i < numberOfValues; i++ {

View File

@ -70,6 +70,14 @@ func TestWalk(t *testing.T) {
},
[]string{"London", "Paris"},
},
{
"maps",
map[string]string{
"Cow": "meuh",
"Sheep": "meh",
},
[]string{"meuh", "meh"},
},
}
for _, test := range cases {