Skip to content

Commit 9f4fa15

Browse files
committed
Change type in generated interfaces and signatures
1 parent 586bde9 commit 9f4fa15

File tree

10 files changed

+150
-96
lines changed

10 files changed

+150
-96
lines changed

cmd/protoc-gen-go-grpc/grpc.go

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,11 @@ func clientSignature(g *protogen.GeneratedFile, method *protogen.Method) string
304304
if !method.Desc.IsStreamingClient() && !method.Desc.IsStreamingServer() {
305305
s += "*" + g.QualifiedGoIdent(method.Output.GoIdent)
306306
} else {
307-
s += method.Parent.GoName + "_" + method.GoName + "Client"
307+
if *useGenericStreams {
308+
s += clientStreamInterface(g, method)
309+
} else {
310+
s += method.Parent.GoName + "_" + method.GoName + "Client"
311+
}
308312
}
309313
s += ", error)"
310314
return s
@@ -358,15 +362,16 @@ func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene
358362
g.P("}")
359363
g.P()
360364

361-
// Stream auxiliary types and methods.
365+
// Auxiliary types aliases, for backwards compatibility.
362366
if *useGenericStreams {
363-
// Use a type alias so that the type name in the generated function
364-
// signature can remain identical even while we swap out the implementation.
367+
g.P("// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.")
365368
g.P("type ", service.GoName, "_", method.GoName, "Client = ", clientStreamInterface(g, method))
366369
g.P()
367370
return
368371
}
369372

373+
// Stream auxiliary types and methods, if we're not taking advantage of the
374+
// pre-implemented generic types and their methods.
370375
genSend := method.Desc.IsStreamingClient()
371376
genRecv := method.Desc.IsStreamingServer()
372377
genCloseAndRecv := !method.Desc.IsStreamingServer()
@@ -426,7 +431,11 @@ func serverSignature(g *protogen.GeneratedFile, method *protogen.Method) string
426431
reqArgs = append(reqArgs, "*"+g.QualifiedGoIdent(method.Input.GoIdent))
427432
}
428433
if method.Desc.IsStreamingClient() || method.Desc.IsStreamingServer() {
429-
reqArgs = append(reqArgs, method.Parent.GoName+"_"+method.GoName+"Server")
434+
if *useGenericStreams {
435+
reqArgs = append(reqArgs, serverStreamInterface(g, method))
436+
} else {
437+
reqArgs = append(reqArgs, method.Parent.GoName+"_"+method.GoName+"Server")
438+
}
430439
}
431440
return method.GoName + "(" + strings.Join(reqArgs, ", ") + ") " + ret
432441
}
@@ -523,15 +532,16 @@ func genServerMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene
523532
g.P("}")
524533
g.P()
525534

526-
// Stream auxiliary types and methods.
535+
// Auxiliary types aliases, for backwards compatibility.
527536
if *useGenericStreams {
528-
// Use a type alias so that the type name in the generated function
529-
// signature can remain identical even while we swap out the implementation.
537+
g.P("// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name.")
530538
g.P("type ", service.GoName, "_", method.GoName, "Server = ", serverStreamInterface(g, method))
531539
g.P()
532540
return hname
533541
}
534542

543+
// Stream auxiliary types and methods, if we're not taking advantage of the
544+
// pre-implemented generic types and their methods.
535545
genSend := method.Desc.IsStreamingServer()
536546
genSendAndClose := !method.Desc.IsStreamingServer()
537547
genRecv := method.Desc.IsStreamingClient()

cmd/protoc-gen-go-grpc/testdata/golden_grpc.pb.go

Lines changed: 18 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)