walk: refacto
This commit is contained in:
parent
049c346e63
commit
1c3ad9b9d8
24
walk/walk.go
24
walk/walk.go
@ -7,22 +7,18 @@ import (
|
|||||||
func Walk(x interface{}, fn func(string)) {
|
func Walk(x interface{}, fn func(string)) {
|
||||||
val := getValue(x)
|
val := getValue(x)
|
||||||
|
|
||||||
for i := 0; i < val.NumField(); i++ {
|
switch val.Kind() {
|
||||||
field := val.Field(i)
|
case reflect.Struct:
|
||||||
|
for i := 0; i < val.NumField(); i++ {
|
||||||
if val.Kind() == reflect.Slice {
|
|
||||||
for i := 0; i < val.Len(); i++ {
|
|
||||||
Walk(val.Index(i).Interface(), fn)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch field.Kind() {
|
|
||||||
case reflect.String:
|
|
||||||
fn(field.String())
|
|
||||||
case reflect.Struct:
|
|
||||||
// XXX: Interface() to get interface
|
// XXX: Interface() to get interface
|
||||||
Walk(field.Interface(), fn)
|
Walk(val.Field(i).Interface(), fn)
|
||||||
}
|
}
|
||||||
|
case reflect.Slice:
|
||||||
|
for i := 0; i < val.Len(); i++ {
|
||||||
|
Walk(val.Index(i).Interface(), fn)
|
||||||
|
}
|
||||||
|
case reflect.String:
|
||||||
|
fn(val.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user