walk: deal with maps
This commit is contained in:
parent
f64d75ca45
commit
61a0d0ff03
@ -19,6 +19,10 @@ func Walk(x interface{}, fn func(string)) {
|
|||||||
case reflect.Slice, reflect.Array:
|
case reflect.Slice, reflect.Array:
|
||||||
numberOfValues = val.Len()
|
numberOfValues = val.Len()
|
||||||
getField = val.Index
|
getField = val.Index
|
||||||
|
case reflect.Map:
|
||||||
|
for _, key := range val.MapKeys() {
|
||||||
|
Walk(val.MapIndex(key).Interface(), fn)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := 0; i < numberOfValues; i++ {
|
for i := 0; i < numberOfValues; i++ {
|
||||||
|
@ -70,6 +70,14 @@ func TestWalk(t *testing.T) {
|
|||||||
},
|
},
|
||||||
[]string{"London", "Paris"},
|
[]string{"London", "Paris"},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"maps",
|
||||||
|
map[string]string{
|
||||||
|
"Cow": "meuh",
|
||||||
|
"Sheep": "meh",
|
||||||
|
},
|
||||||
|
[]string{"meuh", "meh"},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range cases {
|
for _, test := range cases {
|
||||||
|
Loading…
Reference in New Issue
Block a user