cmd/protoc-gen-go-grpc: fix camel-casing of names in generated code
Fix a few points of divergence between the v1 and v2 generators around
when to apply camel-casing to service and method names.
Change-Id: I862f89c0995c540e4862013316d7af772e1ab0d8
Reviewed-on: https://go-review.googlesource.com/c/153658
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
diff --git a/cmd/protoc-gen-go-grpc/internal_gengogrpc/grpc.go b/cmd/protoc-gen-go-grpc/internal_gengogrpc/grpc.go
index 13dd768..dff0877 100644
--- a/cmd/protoc-gen-go-grpc/internal_gengogrpc/grpc.go
+++ b/cmd/protoc-gen-go-grpc/internal_gengogrpc/grpc.go
@@ -150,7 +150,7 @@
continue
}
g.P("{")
- g.P("MethodName: ", strconv.Quote(method.GoName), ",")
+ g.P("MethodName: ", strconv.Quote(string(method.Desc.Name())), ",")
g.P("Handler: ", handlerNames[i], ",")
g.P("},")
}
@@ -161,7 +161,7 @@
continue
}
g.P("{")
- g.P("StreamName: ", strconv.Quote(method.GoName), ",")
+ g.P("StreamName: ", strconv.Quote(string(method.Desc.Name())), ",")
g.P("Handler: ", handlerNames[i], ",")
if method.Desc.IsStreamingServer() {
g.P("ServerStreams: true,")
@@ -298,7 +298,7 @@
g.P("if interceptor == nil { return srv.(", service.GoName, "Server).", method.GoName, "(ctx, in) }")
g.P("info := &", grpcPackage.Ident("UnaryServerInfo"), "{")
g.P("Server: srv,")
- g.P("FullMethod: ", strconv.Quote(fmt.Sprintf("/%s/%s", service.Desc.FullName(), method.Desc.Name())), ",")
+ g.P("FullMethod: ", strconv.Quote(fmt.Sprintf("/%s/%s", service.Desc.FullName(), method.GoName)), ",")
g.P("}")
g.P("handler := func(ctx ", contextPackage.Ident("Context"), ", req interface{}) (interface{}, error) {")
g.P("return srv.(", service.GoName, "Server).", method.GoName, "(ctx, req.(*", method.InputType.GoIdent, "))")
diff --git a/cmd/protoc-gen-go-grpc/testdata/grpc/grpc_grpc.pb.go b/cmd/protoc-gen-go-grpc/testdata/grpc/grpc_grpc.pb.go
index 48c4abd..b638f8c 100644
--- a/cmd/protoc-gen-go-grpc/testdata/grpc/grpc_grpc.pb.go
+++ b/cmd/protoc-gen-go-grpc/testdata/grpc/grpc_grpc.pb.go
@@ -167,7 +167,7 @@
}
info := &grpc.UnaryServerInfo{
Server: srv,
- FullMethod: "/goproto.protoc.grpc.test_service/unary_call",
+ FullMethod: "/goproto.protoc.grpc.test_service/UnaryCall",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TestServiceServer).UnaryCall(ctx, req.(*Request))
@@ -253,23 +253,23 @@
HandlerType: (*TestServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
- MethodName: "UnaryCall",
+ MethodName: "unary_call",
Handler: _TestService_UnaryCall_Handler,
},
},
Streams: []grpc.StreamDesc{
{
- StreamName: "DownstreamCall",
+ StreamName: "downstream_call",
Handler: _TestService_DownstreamCall_Handler,
ServerStreams: true,
},
{
- StreamName: "UpstreamCall",
+ StreamName: "upstream_call",
Handler: _TestService_UpstreamCall_Handler,
ClientStreams: true,
},
{
- StreamName: "BidiCall",
+ StreamName: "bidi_call",
Handler: _TestService_BidiCall_Handler,
ServerStreams: true,
ClientStreams: true,