Better reliability on generated message names

This commit is contained in:
Manfred Touron
2016-12-21 10:32:27 +01:00
parent d0ac6afb18
commit 88a2f47522
3 changed files with 11 additions and 9 deletions

View File

@@ -40,12 +40,12 @@ type grpcServer struct {
}
{{range .Service.Method}}
func (s *grpcServer) {{.Name}}(ctx context.Context, req *pb.{{.Name}}Request) (*pb.{{.Name}}Response, error) {
func (s *grpcServer) {{.Name}}(ctx context.Context, req *pb.{{.InputType | splitArray "." | last}}) (*pb.{{.OutputType | splitArray "." | last}}, error) {
_, rep, err := s.{{.Name | lower}}.ServeGRPC(ctx, req)
if err != nil {
return nil, err
}
return rep.(*pb.{{.Name}}Response), nil
return rep.(*pb.{{.OutputType | splitArray "." | last}}), nil
}
func decode{{.Name}}Request(ctx context.Context, grpcReq interface{}) (interface{}, error) {
@@ -53,7 +53,7 @@ func decode{{.Name}}Request(ctx context.Context, grpcReq interface{}) (interface
}
func encode{{.Name}}Response(ctx context.Context, response interface{}) (interface{}, error) {
resp := response.(*pb.{{.Name}}Response)
resp := response.(*pb.{{.OutputType | splitArray "." | last}})
return resp, nil
}
{{end}}

View File

@@ -26,7 +26,7 @@ func Make{{.Name}}Handler(ctx context.Context, svc pb.{{$file.Package | title}}S
}
func decode{{.Name}}Request(ctx context.Context, r *http.Request) (interface{}, error) {
var req pb.{{.Name}}Request
var req pb.{{.InputType | splitArray "." | last}}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
return nil, err
}