From 4875a9916be10f3ef51da93e7ddd8afcf67d72ef Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Wed, 30 Jul 2014 21:17:46 +0300 Subject: [PATCH] structure: check for pointer structs --- structure.go | 9 +++++---- structure_test.go | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/structure.go b/structure.go index c4fbd3e..b8b347c 100644 --- a/structure.go +++ b/structure.go @@ -29,7 +29,8 @@ func Map(s interface{}) map[string]interface{} { val := v.Field(i) var finalVal interface{} - if val.Kind() == reflect.Struct { + + if IsStruct(val.Interface()) { // look out for embedded structs, and convert them to a // map[string]interface{} too finalVal = Map(val.Interface()) @@ -64,7 +65,7 @@ func Values(s interface{}) []interface{} { t := make([]interface{}, 0) for i := range fields { val := v.Field(i) - if val.Kind() == reflect.Struct { + if IsStruct(val.Interface()) { // look out for embedded structs, and convert them to a // []interface{} to be added to the final values slice for _, embeddedVal := range Values(val.Interface()) { @@ -93,7 +94,7 @@ func IsZero(s interface{}) bool { for i := range fields { val := v.Field(i) - if val.Kind() == reflect.Struct { + if IsStruct(val.Interface()) { ok := IsZero(val.Interface()) if !ok { return false @@ -130,7 +131,7 @@ func Fields(s interface{}) []string { keys := make([]string, 0) for i, field := range fields { val := v.Field(i) - if val.Kind() == reflect.Struct { + if IsStruct(val.Interface()) { // look out for embedded structs, and convert them to a // []string to be added to the final values slice for _, embeddedVal := range Fields(val.Interface()) { diff --git a/structure_test.go b/structure_test.go index 5535613..3972581 100644 --- a/structure_test.go +++ b/structure_test.go @@ -93,10 +93,10 @@ func TestMap_Nested(t *testing.T) { type A struct { Name string } - a := A{Name: "example"} + a := &A{Name: "example"} type B struct { - A A + A *A } b := &B{A: a}