diff --git a/walk/walk.go b/walk/walk.go index df0e449..c3125f6 100644 --- a/walk/walk.go +++ b/walk/walk.go @@ -6,6 +6,7 @@ import ( func Walk(x interface{}, fn func(string)) { val := reflect.ValueOf(x) - field := val.Field(0) - fn(field.String()) + for i := 0; i < val.NumField(); i++ { + fn(val.Field(i).String()) + } } diff --git a/walk/walk_test.go b/walk/walk_test.go index 0fb02b3..1ded3e4 100644 --- a/walk/walk_test.go +++ b/walk/walk_test.go @@ -18,6 +18,14 @@ func TestWalk(t *testing.T) { }{"Chris"}, []string{"Chris"}, }, + { + "struct with two string fields", + struct { + Name string + City string + }{"Chris", "London"}, + []string{"Chris", "London"}, + }, } for _, test := range cases {