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}}