diff --git a/walk/walk.go b/walk/walk.go index 10777d7..d6e80ed 100644 --- a/walk/walk.go +++ b/walk/walk.go @@ -7,18 +7,23 @@ import ( func Walk(x interface{}, fn func(string)) { val := getValue(x) + numberOfValues := 0 + var getField func(int) reflect.Value + switch val.Kind() { - case reflect.Struct: - for i := 0; i < val.NumField(); i++ { - // XXX: Interface() to get interface - 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()) + case reflect.Struct: + numberOfValues = val.NumField() + getField = val.Field + case reflect.Slice: + numberOfValues = val.Len() + getField = val.Index + } + + for i := 0; i < numberOfValues; i++ { + // XXX: Interface() to get interface + Walk(getField(i).Interface(), fn) } }