diff --git a/filter/filter_impl/generic_filter.go b/filter/filter_impl/generic_filter.go index e38a78499cdf779d6a891ced515adf798a33e2a8..36b4b13186361d85beea0625eeda1ad58c3f2dca 100644 --- a/filter/filter_impl/generic_filter.go +++ b/filter/filter_impl/generic_filter.go @@ -21,6 +21,7 @@ import ( "context" "reflect" "strings" + "time" ) import ( @@ -98,11 +99,12 @@ func struct2MapAll(obj interface{}) interface{} { kind := value.Kind() if kind == reflect.Struct || kind == reflect.Slice || kind == reflect.Map { if value.CanInterface() { - if value.Type().String() == "time.Time" { - setInMap(result, field, value.Interface()) - break + tmp := value.Interface() + if _, ok := tmp.(time.Time); ok { + setInMap(result, field, tmp) + continue } - setInMap(result, field, struct2MapAll(value.Interface())) + setInMap(result, field, struct2MapAll(tmp)) } } else { if value.CanInterface() { diff --git a/filter/filter_impl/generic_filter_test.go b/filter/filter_impl/generic_filter_test.go index c8d6f2ec38452fb97f71cde529940372067d1541..40cf743106821f12425d1abe6dbc82bad0559917 100644 --- a/filter/filter_impl/generic_filter_test.go +++ b/filter/filter_impl/generic_filter_test.go @@ -40,6 +40,7 @@ func TestStruct2MapAll(t *testing.T) { } `m:"xxYy"` } `m:"caCa"` DaDa time.Time + EeEe int } testData.AaAa = "1" testData.BaBa = "1" @@ -48,6 +49,7 @@ func TestStruct2MapAll(t *testing.T) { testData.CaCa.XxYy.xxXx = "3" testData.CaCa.XxYy.Xx = "3" testData.DaDa = time.Date(2020, 10, 29, 2, 34, 0, 0, time.Local) + testData.EeEe = 100 m := struct2MapAll(testData).(map[string]interface{}) assert.Equal(t, "1", m["aaAa"].(string)) assert.Equal(t, "1", m["baBa"].(string)) @@ -57,6 +59,7 @@ func TestStruct2MapAll(t *testing.T) { assert.Equal(t, reflect.Map, reflect.TypeOf(m["caCa"]).Kind()) assert.Equal(t, reflect.Map, reflect.TypeOf(m["caCa"].(map[string]interface{})["xxYy"]).Kind()) assert.Equal(t, "2020-10-29 02:34:00", m["daDa"].(time.Time).Format("2006-01-02 15:04:05")) + assert.Equal(t, 100, m["eeEe"].(int)) } type testStruct struct {