From 44edea6b5199aac1cb36130afb90d4925fc67359 Mon Sep 17 00:00:00 2001 From: "huangsimin@fusen.cn" Date: Thu, 7 Dec 2023 17:22:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0handler=E7=9A=84=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../proto_build/tpls/logic_fusen_handler.tpl | 4 ++-- goutils/proto_build/tpls/logic_grpc_struct.tpl | 18 +++++++++++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/goutils/proto_build/tpls/logic_fusen_handler.tpl b/goutils/proto_build/tpls/logic_fusen_handler.tpl index acc11ea..821e3dc 100644 --- a/goutils/proto_build/tpls/logic_fusen_handler.tpl +++ b/goutils/proto_build/tpls/logic_fusen_handler.tpl @@ -10,13 +10,13 @@ import ( {{if eq .MethodType "rpc"}} func (l *{{.StructName}}) {{.MethodName}}Logic({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param}}{{end}}) (resp {{.MethodReturn}},err error) { - return resp, err + return resp, nil } {{else if eq .MethodType "stream"}} func (l *{{.StructName}}) {{.MethodName}}Logic(stream {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param}}{{end}}) (err error) { - return err + return nil } {{end}} diff --git a/goutils/proto_build/tpls/logic_grpc_struct.tpl b/goutils/proto_build/tpls/logic_grpc_struct.tpl index daee0b4..408c23f 100644 --- a/goutils/proto_build/tpls/logic_grpc_struct.tpl +++ b/goutils/proto_build/tpls/logic_grpc_struct.tpl @@ -4,6 +4,7 @@ package {{.PackageName}} import ( "context" "sync" + "fmt" "fusen-basic/env" @@ -47,14 +48,25 @@ type {{.MethodName}}HandlerMust struct{} {{if eq .MethodType "rpc"}} -func (lgrpc *{{.StructName}}Grpc) {{.MethodName}}({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param}}{{end}}) ({{.MethodReturn}}, error) { +func (lgrpc *{{.StructName}}Grpc) {{.MethodName}}({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param}}{{end}}) (_resp {{.MethodReturn}},_err error) { + defer func() { + if _recoverErr := recover(); _recoverErr != nil { + _resp = nil + _err = fmt.Errorf("%v", _recoverErr) + } + }() return New{{.StructName}}(ctx).{{.MethodName}}Logic({{range $index, $param := .ParamsName}}{{if $index}}, {{end}}{{$param}}{{end}}) } {{else if eq .MethodType "stream"}} -func (lgrpc *{{.StructName}}Grpc) {{.MethodName}}(stream {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param}}{{end}}) error { - return New{{.StructName}}(stream.Context()).{{.MethodName}}Logic(stream) +func (lgrpc *{{.StructName}}Grpc) {{.MethodName}}(stream {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param}}{{end}}) (_err error) { + defer func() { + if _recoverErr := recover(); _recoverErr != nil { + _err = fmt.Errorf("%v", _recoverErr) + } + }() + return New{{.StructName}}(stream.Context()).{{.MethodName}}Logic(stream) } {{end}} From 3facd544995617fa4d7bb910f3cb8a7786d7f8e4 Mon Sep 17 00:00:00 2001 From: "huangsimin@fusen.cn" Date: Thu, 7 Dec 2023 17:29:33 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96=E7=9A=84=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- goutils/proto_build/tpls/logic_fusen_handler.tpl | 1 + 1 file changed, 1 insertion(+) diff --git a/goutils/proto_build/tpls/logic_fusen_handler.tpl b/goutils/proto_build/tpls/logic_fusen_handler.tpl index 821e3dc..6ac34b8 100644 --- a/goutils/proto_build/tpls/logic_fusen_handler.tpl +++ b/goutils/proto_build/tpls/logic_fusen_handler.tpl @@ -10,6 +10,7 @@ import ( {{if eq .MethodType "rpc"}} func (l *{{.StructName}}) {{.MethodName}}Logic({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param}}{{end}}) (resp {{.MethodReturn}},err error) { + resp = &{{.MethodResponse}}{} return resp, nil }