支持 stream 序列化 删除gateway的一些垃圾代码
This commit is contained in:
@@ -1,10 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"{{.ProjectName}}/gen/go/service"
|
||||
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func AutoRegisterHandler(ctx context.Context, mux *runtime.ServeMux, opts ...grpc.DialOption) error {
|
||||
var err error
|
||||
{{range .FuncNames}}
|
||||
err = service.{{.}}(ctx, mux, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
{{end}}
|
||||
return nil
|
||||
}
|
||||
@@ -1,10 +1,23 @@
|
||||
package {{.PackageName}}
|
||||
|
||||
import (
|
||||
{{if eq .MethodType "rpc"}}
|
||||
"context"
|
||||
{{end}}
|
||||
"{{.ProjectName}}/gen/go/service"
|
||||
)
|
||||
|
||||
{{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
|
||||
}
|
||||
}
|
||||
|
||||
{{else if eq .MethodType "stream"}}
|
||||
|
||||
func (l *{{.StructName}}) {{.MethodName}}Logic(stream {{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param}}{{end}}) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
{{end}}
|
||||
|
||||
|
||||
@@ -45,9 +45,19 @@ type {{.MethodName}}Handler struct {
|
||||
|
||||
type {{.MethodName}}HandlerMust struct{}
|
||||
|
||||
{{if eq .MethodType "rpc"}}
|
||||
|
||||
func (lgrpc *{{.StructName}}Grpc) {{.MethodName}}({{range $index, $param := .Params}}{{if $index}}, {{end}}{{$param}}{{end}}) ({{.MethodReturn}}, error) {
|
||||
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)
|
||||
}
|
||||
|
||||
{{end}}
|
||||
|
||||
{{end}}
|
||||
|
||||
Reference in New Issue
Block a user