-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protoc: Change protoc to include static method call option #6960
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,7 +170,7 @@ func generateFileContent(gen *protogen.Plugin, file *protogen.File, g *protogen. | |
|
||
g.P("// This is a compile-time assertion to ensure that this generated file") | ||
g.P("// is compatible with the grpc package it is being compiled against.") | ||
g.P("// Requires gRPC-Go v1.32.0 or later.") | ||
g.P("// Requires gRPC-Go v1.32.0 or later.") // TODO: Update to latest released gRPC version | ||
g.P("const _ = ", grpcPackage.Ident("SupportPackageIsVersion7")) // When changing, update version number above. | ||
g.P() | ||
for _, service := range file.Services { | ||
|
@@ -309,9 +309,15 @@ func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene | |
g.P(deprecationComment) | ||
} | ||
g.P("func (c *", unexport(service.GoName), "Client) ", clientSignature(g, method), "{") | ||
g.P("cOpts := make([]", grpcPackage.Ident("CallOption"), ", len(opts))") | ||
g.P("for i, opt := range opts {") | ||
g.P(" cOpts[i] = opt") | ||
g.P("}") | ||
g.P("cOpts = append(cOpts, ", grpcPackage.Ident("RegisteredMethod()"), "\"") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can be simplified to: opts := append([]CallOption{grpc.RegisteredMethod()}, opts...) // shadows `opts` so you don't need the subsequent diffs even Or use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to former. Chose that since less lines of code and get rid of subsequent diffs. |
||
|
||
if !method.Desc.IsStreamingServer() && !method.Desc.IsStreamingClient() { | ||
g.P("out := new(", method.Output.GoIdent, ")") | ||
g.P(`err := c.cc.Invoke(ctx, `, fmSymbol, `, in, out, opts...)`) | ||
g.P(`err := c.cc.Invoke(ctx, `, fmSymbol, `, in, out, cOpts...)`) | ||
g.P("if err != nil { return nil, err }") | ||
g.P("return out, nil") | ||
g.P("}") | ||
|
@@ -320,7 +326,7 @@ func genClientMethod(gen *protogen.Plugin, file *protogen.File, g *protogen.Gene | |
} | ||
streamType := unexport(service.GoName) + method.GoName + "Client" | ||
serviceDescVar := service.GoName + "_ServiceDesc" | ||
g.P("stream, err := c.cc.NewStream(ctx, &", serviceDescVar, ".Streams[", index, `], `, fmSymbol, `, opts...)`) | ||
g.P("stream, err := c.cc.NewStream(ctx, &", serviceDescVar, ".Streams[", index, `], `, fmSymbol, `, cOpts...)`) | ||
g.P("if err != nil { return nil, err }") | ||
g.P("x := &", streamType, "{stream}") | ||
if !method.Desc.IsStreamingClient() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be updated to
Version8
now. The comment just lets users discover more easily whenVersion8
became available.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.