diff --git a/walk/walk.go b/walk/walk.go index c3125f6..1994b84 100644 --- a/walk/walk.go +++ b/walk/walk.go @@ -7,6 +7,8 @@ import ( func Walk(x interface{}, fn func(string)) { val := reflect.ValueOf(x) for i := 0; i < val.NumField(); i++ { - fn(val.Field(i).String()) + if val.Field(i).Kind() == reflect.String { + fn(val.Field(i).String()) + } } } diff --git a/walk/walk_test.go b/walk/walk_test.go index 1ded3e4..d7aa56b 100644 --- a/walk/walk_test.go +++ b/walk/walk_test.go @@ -26,6 +26,14 @@ func TestWalk(t *testing.T) { }{"Chris", "London"}, []string{"Chris", "London"}, }, + { + "struct with non string field", + struct { + Name string + Age int + }{"Chris", 29}, + []string{"Chris"}, + }, } for _, test := range cases {