diff --git a/lego/sys/codec/codec.go b/lego/sys/codec/codec.go index 6ac194841..3fa30b128 100644 --- a/lego/sys/codec/codec.go +++ b/lego/sys/codec/codec.go @@ -100,7 +100,7 @@ func (this *Codec) DecoderOf(typ reflect2.Type) core.IDecoder { Encoders: map[reflect2.Type]core.IEncoder{}, } ptrType := typ.(*reflect2.UnsafePtrType) - decoder = factory.DecoderOfType(ctx, ptrType) + decoder = factory.DecoderOfType(ctx, ptrType.Elem()) this.addDecoderToCache(cacheKey, decoder) return decoder } diff --git a/lego/sys/codec/factory/factory.go b/lego/sys/codec/factory/factory.go index 560cea74c..ca6cf2039 100644 --- a/lego/sys/codec/factory/factory.go +++ b/lego/sys/codec/factory/factory.go @@ -180,7 +180,7 @@ func (this *onePtrEncoder) EncodeToMapJson(ptr unsafe.Pointer) (ret map[string]s err = fmt.Errorf("encoder %T not support EncodeToMapJson", this.encoder) return } else { - return encoderMapJson.EncodeToMapJson(ptr) + return encoderMapJson.EncodeToMapJson(unsafe.Pointer(&ptr)) } } diff --git a/lego/sys/codec/factory/factory_map.go b/lego/sys/codec/factory/factory_map.go index eaf19b4c7..8562b28d1 100644 --- a/lego/sys/codec/factory/factory_map.go +++ b/lego/sys/codec/factory/factory_map.go @@ -84,7 +84,7 @@ type mapEncoder struct { elemEncoder core.IEncoder } -func (codec *mapEncoder) GetType() reflect.Kind { +func (this *mapEncoder) GetType() reflect.Kind { return reflect.Map } func (this *mapEncoder) Encode(ptr unsafe.Pointer, stream core.IStream) { @@ -106,7 +106,7 @@ func (this *mapEncoder) Encode(ptr unsafe.Pointer, stream core.IStream) { stream.WriteObjectEnd() } -func (this *mapEncoder) EncodeToMapString(ptr unsafe.Pointer) (ret map[string]string, err error) { +func (this *mapEncoder) EncodeToMapJson(ptr unsafe.Pointer) (ret map[string]string, err error) { ret = make(map[string]string) keystream := this.codec.BorrowStream() elemstream := this.codec.BorrowStream() diff --git a/lego/sys/codec/factory/factory_optional.go b/lego/sys/codec/factory/factory_optional.go index ff5af87e0..558f7d500 100644 --- a/lego/sys/codec/factory/factory_optional.go +++ b/lego/sys/codec/factory/factory_optional.go @@ -81,7 +81,12 @@ func (this *OptionalEncoder) EncodeToMapJson(ptr unsafe.Pointer) (ret map[string err = fmt.Errorf("encoder %T not support EncodeToMapJson", this.ValueEncoder) return } else { - return encoderMapJson.EncodeToMapJson(ptr) + if *((*unsafe.Pointer)(ptr)) == nil { + err = fmt.Errorf("encoder ptr is nil") + return + } else { + return encoderMapJson.EncodeToMapJson(*((*unsafe.Pointer)(ptr))) + } } } diff --git a/lego/sys/codec/sys_test.go b/lego/sys/codec/sys_test.go index 80e2235f2..321e593e4 100644 --- a/lego/sys/codec/sys_test.go +++ b/lego/sys/codec/sys_test.go @@ -22,6 +22,22 @@ type Test1Data struct { Value int } +func Test_sys_slice(t *testing.T) { + if err := log.OnInit(nil); err != nil { + fmt.Printf("log init err:%v", err) + return + } + if sys, err := codec.NewSys(); err != nil { + fmt.Printf("gin init err:%v", err) + } else { + data := []*Test1Data{{"liwe", 1}, {"liwe2", 2}} + d, err := sys.MarshalJson(data) + fmt.Printf("codec Marshal d:%s err:%v", d, err) + data = []*Test1Data{} + err = sys.UnmarshalJson(d, &data) + fmt.Printf("codec UnmarshalJson data:%v err:%v", data, err) + } +} func Test_sys_json(t *testing.T) { if err := log.OnInit(nil); err != nil { fmt.Printf("log init err:%v", err) diff --git a/modules/comp_model.go b/modules/comp_model.go index d67a3b36c..b666aaf17 100644 --- a/modules/comp_model.go +++ b/modules/comp_model.go @@ -408,8 +408,10 @@ func (this *MCompModel) GetList(uid string, data interface{}) (err error) { } keys[_id] = key } - if err = this.Redis.HMSetForMap(this.ukey(uid), keys); err != nil { - return + if len(keys) > 0 { + if err = this.Redis.HMSet(this.ukey(uid), keys); err != nil { + return + } } } } diff --git a/modules/items/api_getlist.go b/modules/items/api_getlist.go index d66210dbf..b6db05998 100644 --- a/modules/items/api_getlist.go +++ b/modules/items/api_getlist.go @@ -44,7 +44,7 @@ func (this *apiComp) Getlist(session comm.IUserSession, req *pb.ItemsGetlistReq) tempgrids = this.module.configure.GetPackItemByType(items, req.IType) modifys = make([]*pb.DB_UserItemData, 0, len(tempgrids)) dels = make([]string, 0, len(tempgrids)) - grids = make([]*pb.DB_UserItemData, 0, len(grids)) + grids = make([]*pb.DB_UserItemData, 0, len(items)) nt = time.Now().Unix() for _, v := range tempgrids { if v.ETime > 0 && v.ETime < nt { //已经过期 diff --git a/modules/items/module_test.go b/modules/items/module_test.go index 0cd055dd4..448ad187a 100644 --- a/modules/items/module_test.go +++ b/modules/items/module_test.go @@ -83,10 +83,10 @@ func TestMain(m *testing.M) { } func Test_Modules(t *testing.T) { - data, _ := ptypes.MarshalAny(&pb.ItemsGetlistReq{}) - s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62bd7bc609320345a244f372", MainType: "items", SubType: "getlist", Message: data}, &pb.RPCMessageReply{}) - // items, err := module.db_comp.Pack_QueryUserPack("liwei1dao") - log.Debugf("data:%v", data) + data, _ := ptypes.MarshalAny(&pb.ItemsGetlistReq{IType: 9}) + reply := &pb.RPCMessageReply{} + s_gateComp.ReceiveMsg(context.Background(), &pb.AgentMessage{UserId: "0_62cd5952f72cc4bdc2d85f6b", MainType: "items", SubType: "getlist", Message: data}, reply) + log.Debugf("reply:%v", reply) } func Test_Modules_AddItems(t *testing.T) { @@ -95,5 +95,5 @@ func Test_Modules_AddItems(t *testing.T) { FuncName: "Test_Modules_AddItems", Describe: "测试模块接口", }, "0_62c259916d8cf3e4e06311a8", map[int32]int32{10001: 1000}) - log.Debugf("Test_Modules_AddItems:%v code:%v", code) + log.Debugf("Test_Modules_AddItems code:%v", code) } diff --git a/modules/user/api_res.go b/modules/user/api_res.go index f11d64639..817abd5c8 100644 --- a/modules/user/api_res.go +++ b/modules/user/api_res.go @@ -9,7 +9,7 @@ import ( ) func (this *apiComp) AddResCheck(session comm.IUserSession, req *pb.UserAddResReq) (code pb.ErrorCode) { - if req.Res.A == "" || req.Res.T == "" || req.Res.N > 0 { + if req.Res.A == "" || req.Res.T == "" || req.Res.N <= 0 { code = pb.ErrorCode_ReqParameterError } return diff --git a/services/comp_gateroute.go b/services/comp_gateroute.go index 0529b7e9e..fba2e0cbd 100644 --- a/services/comp_gateroute.go +++ b/services/comp_gateroute.go @@ -95,7 +95,7 @@ func (this *SCompGateRoute) RegisterRoute(methodName string, comp reflect.Value, func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessage, reply *pb.RPCMessageReply) (err error) { defer func() { //程序异常 收集异常信息传递给前端显示 if r := recover(); r != nil { - buf := make([]byte, 1024) + buf := make([]byte, 4096) l := runtime.Stack(buf, false) reply.Code = pb.ErrorCode_Exception reply.ErrorMessage = fmt.Sprintf("%v: %s", r, buf[:l]) @@ -130,7 +130,7 @@ func (this *SCompGateRoute) ReceiveMsg(ctx context.Context, args *pb.AgentMessag errcode := pb.ErrorCode(handlereturn[0].Int()) errdata := handlereturn[1].Interface() if errcode != pb.ErrorCode_Success { //处理返货错误码 返回用户错误信息 - log.Errorf("[Handle Api] method:%s uid:%s msg:%v code:%d", method, msg, errcode) + log.Errorf("[Handle Api] method:%s msg:%v code:%d", method, msg, errcode) reply.Code = errcode reply.ErrorMessage = pb.GetErrorCodeMsg(errcode) if errdata != nil { diff --git a/sys/db/benchmark/query_test.go b/sys/db/benchmark/query_test.go index 89f1317bd..99bdeb5e3 100644 --- a/sys/db/benchmark/query_test.go +++ b/sys/db/benchmark/query_test.go @@ -54,8 +54,8 @@ func Test_GetList(t *testing.T) { GetList(&heroes) } func Test_GetList0(t *testing.T) { - heroes := []*DBHero{} - GetListO(&heroes) + // heroes := []*DBHero{} + // GetListO(&heroes) } func BenchmarkMarsh(b *testing.B) {