From 8c1c483462a7478f73db3dcf75021b3a713f6a51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Mon, 26 Oct 2020 09:36:33 -0300 Subject: [PATCH] Improve comments on StructToMap() --- kiss_orm.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/kiss_orm.go b/kiss_orm.go index fcd671c..36b2c1f 100644 --- a/kiss_orm.go +++ b/kiss_orm.go @@ -312,16 +312,19 @@ type structInfo struct { // StructToMap converts any struct type to a map based on // the tag named `gorm`, i.e. `gorm:"map_key_name"` // +// Valid pointers are dereferenced and copied to the map, +// null pointers are ignored. +// // This function is efficient in the fact that it caches -// the slower steps of the reflection required to do perform +// the slower steps of the reflection required to perform // this task. func StructToMap(obj interface{}) (map[string]interface{}, error) { v := reflect.ValueOf(obj) t := v.Type() if t.Kind() == reflect.Ptr { - t = t.Elem() v = v.Elem() + t = t.Elem() } if t.Kind() != reflect.Struct { return nil, fmt.Errorf("input must be a struct or struct pointer")