更新handler的返回值

This commit is contained in:
huangsimin@fusen.cn 2023-12-07 17:22:05 +08:00
parent 61c10dab23
commit 44edea6b51
2 changed files with 17 additions and 5 deletions

View File

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

View File

@ -4,6 +4,7 @@ package {{.PackageName}}
import (
"context"
"sync"
"fmt"
"fusen-basic/env"
@ -47,13 +48,24 @@ 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 {
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)
}