From ef0be4b5bcf5d56e79ce3e2e27728e8e0f134a15 Mon Sep 17 00:00:00 2001 From: franklin Date: Tue, 29 Nov 2022 13:57:04 +0100 Subject: [PATCH] fix: collected nested types --- example/basic/client/src/service-client.ts | 3 +++ example/basic/client/src/service-vo.ts | 10 ++++++++ example/basic/service/gorpc_gen.go | 11 +++++++++ example/basic/service/gorpcclient_gen.go | 11 +++++++++ example/basic/service/gotsrpc_gen.go | 16 +++++++++++++ example/basic/service/gotsrpcclient_gen.go | 11 +++++++++ example/basic/service/service.go | 10 ++++++++ servicereader.go | 27 ++++++++-------------- 8 files changed, 81 insertions(+), 18 deletions(-) diff --git a/example/basic/client/src/service-client.ts b/example/basic/client/src/service-client.ts index 2f01224..59e7e62 100644 --- a/example/basic/client/src/service-client.ts +++ b/example/basic/client/src/service-client.ts @@ -115,6 +115,9 @@ export class ServiceClient { async interfaceSlice(v:Array|null):Promise|null> { return (await this.transport<{0:Array|null}>("InterfaceSlice", [v]))[0] } + async nestedType():Promise { + return (await this.transport<{0:github_com_foomo_gotsrpc_v2_example_basic_service.NestedType|null}>("NestedType", []))[0] + } async string(v:string):Promise { return (await this.transport<{0:string}>("String", [v]))[0] } diff --git a/example/basic/client/src/service-vo.ts b/example/basic/client/src/service-vo.ts index 2a186cf..c22f779 100644 --- a/example/basic/client/src/service-vo.ts +++ b/example/basic/client/src/service-vo.ts @@ -86,6 +86,16 @@ export enum IntTypeMapValue { IntATypeMapValue = 1, IntBTypeMapValue = 2, } +// github.com/foomo/gotsrpc/v2/example/basic/service.NestedSubType +export interface NestedSubType { + Foo:string; +} +// github.com/foomo/gotsrpc/v2/example/basic/service.NestedType +export type NestedType = Record|null>|null> +// github.com/foomo/gotsrpc/v2/example/basic/service.NestedTypeKey +export type NestedTypeKey = string +// github.com/foomo/gotsrpc/v2/example/basic/service.NestedTypeSubKey +export type NestedTypeSubKey = string // github.com/foomo/gotsrpc/v2/example/basic/service.StringType export enum StringType { StringAType = "A", diff --git a/example/basic/service/gorpc_gen.go b/example/basic/service/gorpc_gen.go index 7127c6a..0008ad3 100644 --- a/example/basic/service/gorpc_gen.go +++ b/example/basic/service/gorpc_gen.go @@ -271,6 +271,12 @@ type ( RetInterfaceSlice_0 []interface{} } + ServiceNestedTypeRequest struct { + } + ServiceNestedTypeResponse struct { + RetNestedType_0 NestedType + } + ServiceStringRequest struct { V string } @@ -520,6 +526,8 @@ func init() { gob.Register(ServiceInterfaceResponse{}) gob.Register(ServiceInterfaceSliceRequest{}) gob.Register(ServiceInterfaceSliceResponse{}) + gob.Register(ServiceNestedTypeRequest{}) + gob.Register(ServiceNestedTypeResponse{}) gob.Register(ServiceStringRequest{}) gob.Register(ServiceStringResponse{}) gob.Register(ServiceStringMapRequest{}) @@ -753,6 +761,9 @@ func (p *ServiceGoRPCProxy) handler(clientAddr string, request interface{}) (res req := request.(ServiceInterfaceSliceRequest) retInterfaceSlice_0 := p.service.InterfaceSlice(req.V) response = ServiceInterfaceSliceResponse{RetInterfaceSlice_0: retInterfaceSlice_0} + case "ServiceNestedTypeRequest": + retNestedType_0 := p.service.NestedType() + response = ServiceNestedTypeResponse{RetNestedType_0: retNestedType_0} case "ServiceStringRequest": req := request.(ServiceStringRequest) retString_0 := p.service.String(req.V) diff --git a/example/basic/service/gorpcclient_gen.go b/example/basic/service/gorpcclient_gen.go index 25bdbf8..3f4f1f3 100644 --- a/example/basic/service/gorpcclient_gen.go +++ b/example/basic/service/gorpcclient_gen.go @@ -425,6 +425,17 @@ func (tsc *ServiceGoRPCClient) InterfaceSlice(v []interface{}) (retInterfaceSlic return response.RetInterfaceSlice_0, nil } +func (tsc *ServiceGoRPCClient) NestedType() (retNestedType_0 NestedType, clientErr error) { + req := ServiceNestedTypeRequest{} + rpcCallRes, rpcCallErr := tsc.Client.Call(req) + if rpcCallErr != nil { + clientErr = rpcCallErr + return + } + response := rpcCallRes.(ServiceNestedTypeResponse) + return response.RetNestedType_0, nil +} + func (tsc *ServiceGoRPCClient) String(v string) (retString_0 string, clientErr error) { req := ServiceStringRequest{V: v} rpcCallRes, rpcCallErr := tsc.Client.Call(req) diff --git a/example/basic/service/gotsrpc_gen.go b/example/basic/service/gotsrpc_gen.go index cb4cfe8..3449cd1 100644 --- a/example/basic/service/gotsrpc_gen.go +++ b/example/basic/service/gotsrpc_gen.go @@ -47,6 +47,7 @@ const ( ServiceGoTSRPCProxyIntTypeMapTyped = "IntTypeMapTyped" ServiceGoTSRPCProxyInterface = "Interface" ServiceGoTSRPCProxyInterfaceSlice = "InterfaceSlice" + ServiceGoTSRPCProxyNestedType = "NestedType" ServiceGoTSRPCProxyString = "String" ServiceGoTSRPCProxyStringMap = "StringMap" ServiceGoTSRPCProxyStringSlice = "StringSlice" @@ -926,6 +927,21 @@ func (p *ServiceGoTSRPCProxy) ServeHTTP(w http.ResponseWriter, r *http.Request) } gotsrpc.Monitor(w, r, args, rets, callStats) return + case ServiceGoTSRPCProxyNestedType: + var ( + args []interface{} + rets []interface{} + ) + executionStart := time.Now() + nestedTypeRet := p.service.NestedType() + callStats.Execution = time.Since(executionStart) + rets = []interface{}{nestedTypeRet} + if err := gotsrpc.Reply(rets, callStats, r, w); err != nil { + gotsrpc.ErrorCouldNotReply(w) + return + } + gotsrpc.Monitor(w, r, args, rets, callStats) + return case ServiceGoTSRPCProxyString: var ( args []interface{} diff --git a/example/basic/service/gotsrpcclient_gen.go b/example/basic/service/gotsrpcclient_gen.go index 66af171..7416849 100644 --- a/example/basic/service/gotsrpcclient_gen.go +++ b/example/basic/service/gotsrpcclient_gen.go @@ -47,6 +47,7 @@ type ServiceGoTSRPCClient interface { IntTypeMapTyped(ctx go_context.Context, v IntTypeMapTyped) (retIntTypeMapTyped_0 IntTypeMapTyped, clientErr error) Interface(ctx go_context.Context, v interface{}) (retInterface_0 interface{}, clientErr error) InterfaceSlice(ctx go_context.Context, v []interface{}) (retInterfaceSlice_0 []interface{}, clientErr error) + NestedType(ctx go_context.Context) (retNestedType_0 NestedType, clientErr error) String(ctx go_context.Context, v string) (retString_0 string, clientErr error) StringMap(ctx go_context.Context, v map[string]interface{}) (retStringMap_0 map[string]interface{}, clientErr error) StringSlice(ctx go_context.Context, v []string) (retStringSlice_0 []string, clientErr error) @@ -455,6 +456,16 @@ func (tsc *HTTPServiceGoTSRPCClient) InterfaceSlice(ctx go_context.Context, v [] return } +func (tsc *HTTPServiceGoTSRPCClient) NestedType(ctx go_context.Context) (retNestedType_0 NestedType, clientErr error) { + args := []interface{}{} + reply := []interface{}{&retNestedType_0} + clientErr = tsc.Client.Call(ctx, tsc.URL, tsc.EndPoint, "NestedType", args, reply) + if clientErr != nil { + clientErr = pkg_errors.WithMessage(clientErr, "failed to call service.ServiceGoTSRPCProxy NestedType") + } + return +} + func (tsc *HTTPServiceGoTSRPCClient) String(ctx go_context.Context, v string) (retString_0 string, clientErr error) { args := []interface{}{v} reply := []interface{}{&retString_0} diff --git a/example/basic/service/service.go b/example/basic/service/service.go index f707571..5e1ed76 100644 --- a/example/basic/service/service.go +++ b/example/basic/service/service.go @@ -62,4 +62,14 @@ type Service interface { Float32Type(v Float32Type) Float32Type Float64Type(v Float64Type) Float64Type StringType(v StringType) StringType + NestedType() NestedType } + +type ( + NestedType map[NestedTypeKey]map[NestedTypeSubKey][]*NestedSubType + NestedTypeKey string + NestedTypeSubKey string + NestedSubType struct { + Foo string + } +) diff --git a/servicereader.go b/servicereader.go index 4c0171a..0349c07 100644 --- a/servicereader.go +++ b/servicereader.go @@ -631,26 +631,17 @@ func (s *Struct) DepsSatisfied(missingTypes map[string]bool, structs map[string] // } // } //} - if s.Array != nil && s.Array.Value != nil { - if s.Array.Value.StructType != nil { - if needsWork(s.Array.Value.StructType.FullName()) { - return false - } - } else if s.Array.Value.Scalar != nil { - if needsWork(s.Array.Value.Scalar.FullName()) { - return false - } + if s.Array != nil { + if s.Array.Value != nil && needsWorkValue(s.Array.Value, needsWork) { + return false } } - if s.Map != nil && s.Map.Value != nil { - if s.Map.Value.StructType != nil { - if needsWork(s.Map.Value.StructType.FullName()) { - return false - } - } else if s.Map.Value.Scalar != nil { - if needsWork(s.Map.Value.Scalar.FullName()) { - return false - } + if s.Map != nil { + if s.Map.Key != nil && needsWorkValue(s.Map.Key, needsWork) { + return false + } + if s.Map.Value != nil && needsWorkValue(s.Map.Value, needsWork) { + return false } } return !needsWork(s.FullName())