Merge pull request #40 from gocontrib/fix-time-nesting
fix nesting of time fields
This commit is contained in:
commit
9a7733345f
@ -94,7 +94,12 @@ func (s *Struct) Map() map[string]interface{} {
|
|||||||
// map[string]interface{} too
|
// map[string]interface{} too
|
||||||
n := New(val.Interface())
|
n := New(val.Interface())
|
||||||
n.TagName = s.TagName
|
n.TagName = s.TagName
|
||||||
finalVal = n.Map()
|
m := n.Map()
|
||||||
|
if len(m) == 0 {
|
||||||
|
finalVal = val.Interface()
|
||||||
|
} else {
|
||||||
|
finalVal = m
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
finalVal = val.Interface()
|
finalVal = val.Interface()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -296,6 +296,20 @@ func TestMap_Anonymous(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMap_TimeField(t *testing.T) {
|
||||||
|
type A struct {
|
||||||
|
CreatedAt time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
a := &A{CreatedAt: time.Now().UTC()}
|
||||||
|
m := Map(a)
|
||||||
|
|
||||||
|
_, ok := m["CreatedAt"].(time.Time)
|
||||||
|
if !ok {
|
||||||
|
t.Error("Time field must be final")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestStruct(t *testing.T) {
|
func TestStruct(t *testing.T) {
|
||||||
var T = struct{}{}
|
var T = struct{}{}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user