From a29cc61dc670ab410e99d7698d89a5ab4db8f9cd Mon Sep 17 00:00:00 2001 From: Matrix-X Date: Wed, 8 Jun 2022 16:44:20 +0800 Subject: [PATCH] feature(object): add object type pionter creater --- object/hashMap.go | 13 +++++++++++++ object/object.go | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/object/hashMap.go b/object/hashMap.go index 05fddc7..42c2a77 100644 --- a/object/hashMap.go +++ b/object/hashMap.go @@ -158,6 +158,19 @@ func FilterEmptyHashMap(mapData *HashMap) (filteredMap *HashMap) { case *HashMap: v = FilterEmptyHashMap(v.(*HashMap)) break + //case []interface{}: + // for _, obj := range v.([]interface{}) { + // switch obj.(type) { + // case map[string]interface{}: + // o, _ := StructToHashMap(obj) + // v = FilterEmptyHashMap(o) + // break + // default: + // + // } + // } + // break + case string: if v.(string) == "" { delete(*filteredMap, k) diff --git a/object/object.go b/object/object.go index 8407ead..7ce0a98 100644 --- a/object/object.go +++ b/object/object.go @@ -5,6 +5,7 @@ import ( "encoding/gob" "fmt" "log" + "time" ) func EncodeToBytes(p interface{}) []byte { @@ -16,4 +17,39 @@ func EncodeToBytes(p interface{}) []byte { } fmt.Println("uncompressed size (bytes): ", len(buf.Bytes())) return buf.Bytes() -} \ No newline at end of file +} + +// Time 复制 time.Time 对象,并返回复制体的指针 +func Time(t time.Time) *time.Time { + return &t +} + +// String 复制 string 对象,并返回复制体的指针 +func String(s string) *string { + return &s +} + +// Bool 复制 bool 对象,并返回复制体的指针 +func Bool(b bool) *bool { + return &b +} + +// Float64 复制 float64 对象,并返回复制体的指针 +func Float64(f float64) *float64 { + return &f +} + +// Float32 复制 float32 对象,并返回复制体的指针 +func Float32(f float32) *float32 { + return &f +} + +// Int64 复制 int64 对象,并返回复制体的指针 +func Int64(i int64) *int64 { + return &i +} + +// Int32 复制 int64 对象,并返回复制体的指针 +func Int32(i int32) *int32 { + return &i +}