From 18edbbad87a08ae42a9d71e5c04dd51d68be44cc Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 10 Aug 2022 19:28:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=AD=A6=E5=99=A8=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=95=B0=E6=8D=AE=E5=BA=93=E6=8A=A5=E9=94=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E4=BB=A5=E5=8F=8A=E6=97=A5=E5=BF=97=E5=A0=86?= =?UTF-8?q?=E6=A0=88=E4=BF=A1=E6=81=AF=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lego/sys/log/options.go | 4 ++-- lego/utils/codec/json/json_test.go | 38 ++++++++++++++++++++++++++++++ modules/options.go | 2 +- sys/db/dbconn.go | 3 ++- 4 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 lego/utils/codec/json/json_test.go diff --git a/lego/sys/log/options.go b/lego/sys/log/options.go index a0c5e8815..0073a56c5 100644 --- a/lego/sys/log/options.go +++ b/lego/sys/log/options.go @@ -102,7 +102,7 @@ func newOptions(config map[string]interface{}, opts ...Option) (options *Options MaxBackups: 250, Compress: false, Encoder: TextEncoder, - CallerSkip: 0, + CallerSkip: 3, ReportCaller: ErrorLevel, IsDebug: true, } @@ -128,7 +128,7 @@ func newOptionsByOption(opts ...Option) (options *Options, err error) { MaxBackups: 250, Compress: false, Encoder: TextEncoder, - CallerSkip: 0, + CallerSkip: 3, ReportCaller: ErrorLevel, IsDebug: true, } diff --git a/lego/utils/codec/json/json_test.go b/lego/utils/codec/json/json_test.go new file mode 100644 index 000000000..f3552f843 --- /dev/null +++ b/lego/utils/codec/json/json_test.go @@ -0,0 +1,38 @@ +package json_test + +import ( + "fmt" + "go_dreamfactory/lego/utils/codec/json" + "testing" +) + +type TestData struct { + Name string + Age int + List []string + Map map[string]interface{} +} + +//测试api_getlist +func Test_Json_Write(t *testing.T) { + ret, err := json.MarshalMap(&TestData{ + Name: "liwei", + Age: 10, + List: []string{"123", "456", "789"}, + Map: map[string]interface{}{ + "aa": 123, + "b": "123123", + }, + }) + fmt.Printf("ret:%v err:%v", ret, err) + ret, err = json.MarshalMap(&TestData{ + Name: "asdasd", + Age: 10, + List: []string{"12asd3", "45sdaa6", "asdasd"}, + Map: map[string]interface{}{ + "asd": 586, + "asdasd": "asd1231", + }, + }) + fmt.Printf("ret:%v err:%v", ret, err) +} diff --git a/modules/options.go b/modules/options.go index c2479d720..2922bb262 100644 --- a/modules/options.go +++ b/modules/options.go @@ -33,7 +33,7 @@ func (this *Options) LoadConfig(settings map[string]interface{}) (err error) { err = mapstructure.Decode(settings, this) } - if this.Log = log.NewTurnlog(this.Debug, log.Clone("", 2)); this.Log == nil { + if this.Log = log.NewTurnlog(this.Debug, log.Clone("", 3)); this.Log == nil { err = errors.New("log is nil") } return diff --git a/sys/db/dbconn.go b/sys/db/dbconn.go index f778f174c..02da6a53e 100644 --- a/sys/db/dbconn.go +++ b/sys/db/dbconn.go @@ -190,7 +190,7 @@ func (this *DBModel) AddLists(uid string, data interface{}, opt ...DBOption) (er } listskeys := make(map[string]string) keys := vof.MapKeys() - lists := make([]interface{}, len(keys)) + lists := make([]interface{}, 0, len(keys)) pipe := this.Redis.RedisPipe(context.TODO()) for _, k := range keys { value := vof.MapIndex(k) @@ -199,6 +199,7 @@ func (this *DBModel) AddLists(uid string, data interface{}, opt ...DBOption) (er key := this.ukeylist(uid, keydata) pipe.HMSet(key, valuedata) listskeys[keydata] = key + lists = append(lists, valuedata) } pipe.HMSetForMap(this.ukey(uid), listskeys) if _, err = pipe.Exec(); err != nil {