From fc3249ededb77eaaf190f928adb9d491e3692869 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Mon, 1 Jun 2020 13:39:45 -0700 Subject: [PATCH 1/8] protoc-gen-go-grpc: add requirement of embedding Unimplemented___Server for services --- .../grpclb/grpc_lb_v1/load_balancer_grpc.pb.go | 6 +++++- balancer/grpclb/grpclb_test.go | 1 + .../proto/grpc_lookup_v1/rls_grpc.pb.go | 6 +++++- .../testutils/fakeserver/fakeserver.go | 1 + benchmark/benchmark.go | 2 ++ benchmark/grpc_testing/services_grpc.pb.go | 12 ++++++++++-- benchmark/worker/main.go | 1 + channelz/grpc_channelz_v1/channelz_grpc.pb.go | 6 +++++- channelz/service/service.go | 4 +++- cmd/protoc-gen-go-grpc/grpc.go | 8 +++++++- cmd/protoc-gen-go-grpc/main.go | 11 ++++++++++- .../proto/grpc_gcp/handshaker_grpc.pb.go | 6 +++++- examples/features/proto/echo/echo_grpc.pb.go | 6 +++++- .../helloworld/helloworld_grpc.pb.go | 6 +++++- .../routeguide/route_guide_grpc.pb.go | 6 +++++- health/grpc_health_v1/health_grpc.pb.go | 6 +++++- health/server.go | 1 + interop/fake_grpclb/fake_grpclb.go | 1 + interop/grpc_testing/test_grpc.pb.go | 18 +++++++++++++++--- interop/test_utils.go | 1 + interop/xds/client/client.go | 4 +++- profiling/proto/service_grpc.pb.go | 6 +++++- profiling/service/service.go | 1 + .../reflection_grpc.pb.go | 6 +++++- reflection/grpc_testing/test_grpc.pb.go | 6 +++++- reflection/serverreflection.go | 1 + stats/grpc_testing/test_grpc.pb.go | 6 +++++- stress/client/main.go | 1 + stress/grpc_testing/metrics_grpc.pb.go | 6 +++++- test/grpc_testing/test_grpc.pb.go | 6 +++++- 30 files changed, 129 insertions(+), 23 deletions(-) diff --git a/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go b/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go index 40cbf5724563..ed0d9c1d4d2b 100644 --- a/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go +++ b/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go @@ -61,18 +61,22 @@ func (x *loadBalancerBalanceLoadClient) Recv() (*LoadBalanceResponse, error) { } // LoadBalancerServer is the server API for LoadBalancer service. +// All implementations must embed UnimplementedLoadBalancerServer +// for forward compatibility type LoadBalancerServer interface { // Bidirectional rpc to get a list of servers. BalanceLoad(LoadBalancer_BalanceLoadServer) error + _unimplementedLoadBalancerServer() } -// UnimplementedLoadBalancerServer can be embedded to have forward compatible implementations. +// UnimplementedLoadBalancerServer must be embedded to have forward compatible implementations. type UnimplementedLoadBalancerServer struct { } func (*UnimplementedLoadBalancerServer) BalanceLoad(LoadBalancer_BalanceLoadServer) error { return status.Errorf(codes.Unimplemented, "method BalanceLoad not implemented") } +func (*UnimplementedLoadBalancerServer) _unimplementedLoadBalancerServer() {} func RegisterLoadBalancerServer(s *grpc.Server, srv LoadBalancerServer) { s.RegisterService(&_LoadBalancer_serviceDesc, srv) diff --git a/balancer/grpclb/grpclb_test.go b/balancer/grpclb/grpclb_test.go index d701b6d216a0..45d2df64567f 100644 --- a/balancer/grpclb/grpclb_test.go +++ b/balancer/grpclb/grpclb_test.go @@ -187,6 +187,7 @@ func (s *rpcStats) String() string { } type remoteBalancer struct { + lbgrpc.UnimplementedLoadBalancerServer sls chan *lbpb.ServerList statsDura time.Duration done chan struct{} diff --git a/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go b/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go index 6e4145dd5fc4..7a1fb41e937d 100644 --- a/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go +++ b/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go @@ -39,18 +39,22 @@ func (c *routeLookupServiceClient) RouteLookup(ctx context.Context, in *RouteLoo } // RouteLookupServiceServer is the server API for RouteLookupService service. +// All implementations must embed UnimplementedRouteLookupServiceServer +// for forward compatibility type RouteLookupServiceServer interface { // Lookup returns a target for a single key. RouteLookup(context.Context, *RouteLookupRequest) (*RouteLookupResponse, error) + _unimplementedRouteLookupServiceServer() } -// UnimplementedRouteLookupServiceServer can be embedded to have forward compatible implementations. +// UnimplementedRouteLookupServiceServer must be embedded to have forward compatible implementations. type UnimplementedRouteLookupServiceServer struct { } func (*UnimplementedRouteLookupServiceServer) RouteLookup(context.Context, *RouteLookupRequest) (*RouteLookupResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RouteLookup not implemented") } +func (*UnimplementedRouteLookupServiceServer) _unimplementedRouteLookupServiceServer() {} func RegisterRouteLookupServiceServer(s *grpc.Server, srv RouteLookupServiceServer) { s.RegisterService(&_RouteLookupService_serviceDesc, srv) diff --git a/balancer/rls/internal/testutils/fakeserver/fakeserver.go b/balancer/rls/internal/testutils/fakeserver/fakeserver.go index 93947da4ccef..479e3036468f 100644 --- a/balancer/rls/internal/testutils/fakeserver/fakeserver.go +++ b/balancer/rls/internal/testutils/fakeserver/fakeserver.go @@ -49,6 +49,7 @@ type Response struct { // Server is a fake implementation of RLS. It exposes channels to send/receive // RLS requests and responses. type Server struct { + rlsgrpc.UnimplementedRouteLookupServiceServer RequestChan *testutils.Channel ResponseChan chan Response Address string diff --git a/benchmark/benchmark.go b/benchmark/benchmark.go index e844bb1ea52d..d82b61c9c619 100644 --- a/benchmark/benchmark.go +++ b/benchmark/benchmark.go @@ -60,6 +60,7 @@ func NewPayload(t testpb.PayloadType, size int) *testpb.Payload { } type testServer struct { + testpb.UnimplementedBenchmarkServiceServer } func (s *testServer) UnaryCall(ctx context.Context, in *testpb.SimpleRequest) (*testpb.SimpleResponse, error) { @@ -141,6 +142,7 @@ func (s *testServer) UnconstrainedStreamingCall(stream testpb.BenchmarkService_U // byteBufServer is a gRPC server that sends and receives byte buffer. // The purpose is to benchmark the gRPC performance without protobuf serialization/deserialization overhead. type byteBufServer struct { + testpb.UnimplementedBenchmarkServiceServer respSize int32 } diff --git a/benchmark/grpc_testing/services_grpc.pb.go b/benchmark/grpc_testing/services_grpc.pb.go index e923f72c5387..6e08399fb990 100644 --- a/benchmark/grpc_testing/services_grpc.pb.go +++ b/benchmark/grpc_testing/services_grpc.pb.go @@ -108,6 +108,8 @@ func (x *benchmarkServiceUnconstrainedStreamingCallClient) Recv() (*SimpleRespon } // BenchmarkServiceServer is the server API for BenchmarkService service. +// All implementations must embed UnimplementedBenchmarkServiceServer +// for forward compatibility type BenchmarkServiceServer interface { // One request followed by one response. // The server returns the client payload as-is. @@ -118,9 +120,10 @@ type BenchmarkServiceServer interface { // Unconstrainted streaming. // Both server and client keep sending & receiving simultaneously. UnconstrainedStreamingCall(BenchmarkService_UnconstrainedStreamingCallServer) error + _unimplementedBenchmarkServiceServer() } -// UnimplementedBenchmarkServiceServer can be embedded to have forward compatible implementations. +// UnimplementedBenchmarkServiceServer must be embedded to have forward compatible implementations. type UnimplementedBenchmarkServiceServer struct { } @@ -133,6 +136,7 @@ func (*UnimplementedBenchmarkServiceServer) StreamingCall(BenchmarkService_Strea func (*UnimplementedBenchmarkServiceServer) UnconstrainedStreamingCall(BenchmarkService_UnconstrainedStreamingCallServer) error { return status.Errorf(codes.Unimplemented, "method UnconstrainedStreamingCall not implemented") } +func (*UnimplementedBenchmarkServiceServer) _unimplementedBenchmarkServiceServer() {} func RegisterBenchmarkServiceServer(s *grpc.Server, srv BenchmarkServiceServer) { s.RegisterService(&_BenchmarkService_serviceDesc, srv) @@ -347,6 +351,8 @@ func (c *workerServiceClient) QuitWorker(ctx context.Context, in *Void, opts ... } // WorkerServiceServer is the server API for WorkerService service. +// All implementations must embed UnimplementedWorkerServiceServer +// for forward compatibility type WorkerServiceServer interface { // Start server with specified workload. // First request sent specifies the ServerConfig followed by ServerStatus @@ -366,9 +372,10 @@ type WorkerServiceServer interface { CoreCount(context.Context, *CoreRequest) (*CoreResponse, error) // Quit this worker QuitWorker(context.Context, *Void) (*Void, error) + _unimplementedWorkerServiceServer() } -// UnimplementedWorkerServiceServer can be embedded to have forward compatible implementations. +// UnimplementedWorkerServiceServer must be embedded to have forward compatible implementations. type UnimplementedWorkerServiceServer struct { } @@ -384,6 +391,7 @@ func (*UnimplementedWorkerServiceServer) CoreCount(context.Context, *CoreRequest func (*UnimplementedWorkerServiceServer) QuitWorker(context.Context, *Void) (*Void, error) { return nil, status.Errorf(codes.Unimplemented, "method QuitWorker not implemented") } +func (*UnimplementedWorkerServiceServer) _unimplementedWorkerServiceServer() {} func RegisterWorkerServiceServer(s *grpc.Server, srv WorkerServiceServer) { s.RegisterService(&_WorkerService_serviceDesc, srv) diff --git a/benchmark/worker/main.go b/benchmark/worker/main.go index 2b760f54f9fa..fba451c4f27b 100644 --- a/benchmark/worker/main.go +++ b/benchmark/worker/main.go @@ -73,6 +73,7 @@ func (byteBufCodec) String() string { // workerServer implements WorkerService rpc handlers. // It can create benchmarkServer or benchmarkClient on demand. type workerServer struct { + testpb.UnimplementedWorkerServiceServer stop chan<- bool serverPort int } diff --git a/channelz/grpc_channelz_v1/channelz_grpc.pb.go b/channelz/grpc_channelz_v1/channelz_grpc.pb.go index bacb448d1d85..d96668ac8707 100644 --- a/channelz/grpc_channelz_v1/channelz_grpc.pb.go +++ b/channelz/grpc_channelz_v1/channelz_grpc.pb.go @@ -106,6 +106,8 @@ func (c *channelzClient) GetSocket(ctx context.Context, in *GetSocketRequest, op } // ChannelzServer is the server API for Channelz service. +// All implementations must embed UnimplementedChannelzServer +// for forward compatibility type ChannelzServer interface { // Gets all root channels (i.e. channels the application has directly // created). This does not include subchannels nor non-top level channels. @@ -122,9 +124,10 @@ type ChannelzServer interface { GetSubchannel(context.Context, *GetSubchannelRequest) (*GetSubchannelResponse, error) // Returns a single Socket or else a NOT_FOUND code. GetSocket(context.Context, *GetSocketRequest) (*GetSocketResponse, error) + _unimplementedChannelzServer() } -// UnimplementedChannelzServer can be embedded to have forward compatible implementations. +// UnimplementedChannelzServer must be embedded to have forward compatible implementations. type UnimplementedChannelzServer struct { } @@ -149,6 +152,7 @@ func (*UnimplementedChannelzServer) GetSubchannel(context.Context, *GetSubchanne func (*UnimplementedChannelzServer) GetSocket(context.Context, *GetSocketRequest) (*GetSocketResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetSocket not implemented") } +func (*UnimplementedChannelzServer) _unimplementedChannelzServer() {} func RegisterChannelzServer(s *grpc.Server, srv ChannelzServer) { s.RegisterService(&_Channelz_serviceDesc, srv) diff --git a/channelz/service/service.go b/channelz/service/service.go index b7650b3b29fa..702b74c03e60 100644 --- a/channelz/service/service.go +++ b/channelz/service/service.go @@ -48,7 +48,9 @@ func newCZServer() channelzgrpc.ChannelzServer { return &serverImpl{} } -type serverImpl struct{} +type serverImpl struct { + channelzgrpc.UnimplementedChannelzServer +} func connectivityStateToProto(s connectivity.State) *channelzpb.ChannelConnectivityState { switch s { diff --git a/cmd/protoc-gen-go-grpc/grpc.go b/cmd/protoc-gen-go-grpc/grpc.go index 38d444fc7a1d..7db8597b4d53 100644 --- a/cmd/protoc-gen-go-grpc/grpc.go +++ b/cmd/protoc-gen-go-grpc/grpc.go @@ -122,6 +122,8 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated // Server interface. serverType := service.GoName + "Server" g.P("// ", serverType, " is the server API for ", service.GoName, " service.") + g.P("// All implementations must embed Unimplemented", serverType) + g.P("// for forward compatibility") if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { g.P("//") g.P(deprecationComment) @@ -136,11 +138,14 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P(method.Comments.Leading, serverSignature(g, method)) } + if *requireUnimplemented { + g.P("_unimplemented", serverType, "()") + } g.P("}") g.P() // Server Unimplemented struct for forward compatibility. - g.P("// Unimplemented", serverType, " can be embedded to have forward compatible implementations.") + g.P("// Unimplemented", serverType, " must be embedded to have forward compatible implementations.") g.P("type Unimplemented", serverType, " struct {") g.P("}") g.P() @@ -153,6 +158,7 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P("return ", nilArg, statusPackage.Ident("Errorf"), "(", codesPackage.Ident("Unimplemented"), `, "method `, method.GoName, ` not implemented")`) g.P("}") } + g.P("func (*Unimplemented", serverType, ") _unimplemented", serverType, "() {}") g.P() // Server registration. diff --git a/cmd/protoc-gen-go-grpc/main.go b/cmd/protoc-gen-go-grpc/main.go index dac0be207e23..a8555fad23a1 100644 --- a/cmd/protoc-gen-go-grpc/main.go +++ b/cmd/protoc-gen-go-grpc/main.go @@ -31,11 +31,20 @@ package main import ( + "flag" + "google.golang.org/protobuf/compiler/protogen" ) +var requireUnimplemented *bool + func main() { - protogen.Options{}.Run(func(gen *protogen.Plugin) error { + var flags flag.FlagSet + requireUnimplemented = flags.Bool("requireUnimplementedServers", true, "unset to match legacy behavior") + + protogen.Options{ + ParamFunc: flags.Set, + }.Run(func(gen *protogen.Plugin) error { for _, f := range gen.Files { if !f.Generate { continue diff --git a/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go b/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go index 75c2e4732439..3809a101a4cd 100644 --- a/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go +++ b/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go @@ -66,6 +66,8 @@ func (x *handshakerServiceDoHandshakeClient) Recv() (*HandshakerResp, error) { } // HandshakerServiceServer is the server API for HandshakerService service. +// All implementations must embed UnimplementedHandshakerServiceServer +// for forward compatibility type HandshakerServiceServer interface { // Handshaker service accepts a stream of handshaker request, returning a // stream of handshaker response. Client is expected to send exactly one @@ -74,15 +76,17 @@ type HandshakerServiceServer interface { // service expects to respond. Client does not have to wait for service's // response before sending next request. DoHandshake(HandshakerService_DoHandshakeServer) error + _unimplementedHandshakerServiceServer() } -// UnimplementedHandshakerServiceServer can be embedded to have forward compatible implementations. +// UnimplementedHandshakerServiceServer must be embedded to have forward compatible implementations. type UnimplementedHandshakerServiceServer struct { } func (*UnimplementedHandshakerServiceServer) DoHandshake(HandshakerService_DoHandshakeServer) error { return status.Errorf(codes.Unimplemented, "method DoHandshake not implemented") } +func (*UnimplementedHandshakerServiceServer) _unimplementedHandshakerServiceServer() {} func RegisterHandshakerServiceServer(s *grpc.Server, srv HandshakerServiceServer) { s.RegisterService(&_HandshakerService_serviceDesc, srv) diff --git a/examples/features/proto/echo/echo_grpc.pb.go b/examples/features/proto/echo/echo_grpc.pb.go index 38be6f65ce1a..b5308262e80a 100644 --- a/examples/features/proto/echo/echo_grpc.pb.go +++ b/examples/features/proto/echo/echo_grpc.pb.go @@ -142,6 +142,8 @@ func (x *echoBidirectionalStreamingEchoClient) Recv() (*EchoResponse, error) { } // EchoServer is the server API for Echo service. +// All implementations must embed UnimplementedEchoServer +// for forward compatibility type EchoServer interface { // UnaryEcho is unary echo. UnaryEcho(context.Context, *EchoRequest) (*EchoResponse, error) @@ -151,9 +153,10 @@ type EchoServer interface { ClientStreamingEcho(Echo_ClientStreamingEchoServer) error // BidirectionalStreamingEcho is bidi streaming. BidirectionalStreamingEcho(Echo_BidirectionalStreamingEchoServer) error + _unimplementedEchoServer() } -// UnimplementedEchoServer can be embedded to have forward compatible implementations. +// UnimplementedEchoServer must be embedded to have forward compatible implementations. type UnimplementedEchoServer struct { } @@ -169,6 +172,7 @@ func (*UnimplementedEchoServer) ClientStreamingEcho(Echo_ClientStreamingEchoServ func (*UnimplementedEchoServer) BidirectionalStreamingEcho(Echo_BidirectionalStreamingEchoServer) error { return status.Errorf(codes.Unimplemented, "method BidirectionalStreamingEcho not implemented") } +func (*UnimplementedEchoServer) _unimplementedEchoServer() {} func RegisterEchoServer(s *grpc.Server, srv EchoServer) { s.RegisterService(&_Echo_serviceDesc, srv) diff --git a/examples/helloworld/helloworld/helloworld_grpc.pb.go b/examples/helloworld/helloworld/helloworld_grpc.pb.go index ac81352958cb..0d5b27e19c6e 100644 --- a/examples/helloworld/helloworld/helloworld_grpc.pb.go +++ b/examples/helloworld/helloworld/helloworld_grpc.pb.go @@ -39,18 +39,22 @@ func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ... } // GreeterServer is the server API for Greeter service. +// All implementations must embed UnimplementedGreeterServer +// for forward compatibility type GreeterServer interface { // Sends a greeting SayHello(context.Context, *HelloRequest) (*HelloReply, error) + _unimplementedGreeterServer() } -// UnimplementedGreeterServer can be embedded to have forward compatible implementations. +// UnimplementedGreeterServer must be embedded to have forward compatible implementations. type UnimplementedGreeterServer struct { } func (*UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } +func (*UnimplementedGreeterServer) _unimplementedGreeterServer() {} func RegisterGreeterServer(s *grpc.Server, srv GreeterServer) { s.RegisterService(&_Greeter_serviceDesc, srv) diff --git a/examples/route_guide/routeguide/route_guide_grpc.pb.go b/examples/route_guide/routeguide/route_guide_grpc.pb.go index 326a7683ef0d..e2a74cf0bbd9 100644 --- a/examples/route_guide/routeguide/route_guide_grpc.pb.go +++ b/examples/route_guide/routeguide/route_guide_grpc.pb.go @@ -158,6 +158,8 @@ func (x *routeGuideRouteChatClient) Recv() (*RouteNote, error) { } // RouteGuideServer is the server API for RouteGuide service. +// All implementations must embed UnimplementedRouteGuideServer +// for forward compatibility type RouteGuideServer interface { // A simple RPC. // @@ -183,9 +185,10 @@ type RouteGuideServer interface { // Accepts a stream of RouteNotes sent while a route is being traversed, // while receiving other RouteNotes (e.g. from other users). RouteChat(RouteGuide_RouteChatServer) error + _unimplementedRouteGuideServer() } -// UnimplementedRouteGuideServer can be embedded to have forward compatible implementations. +// UnimplementedRouteGuideServer must be embedded to have forward compatible implementations. type UnimplementedRouteGuideServer struct { } @@ -201,6 +204,7 @@ func (*UnimplementedRouteGuideServer) RecordRoute(RouteGuide_RecordRouteServer) func (*UnimplementedRouteGuideServer) RouteChat(RouteGuide_RouteChatServer) error { return status.Errorf(codes.Unimplemented, "method RouteChat not implemented") } +func (*UnimplementedRouteGuideServer) _unimplementedRouteGuideServer() {} func RegisterRouteGuideServer(s *grpc.Server, srv RouteGuideServer) { s.RegisterService(&_RouteGuide_serviceDesc, srv) diff --git a/health/grpc_health_v1/health_grpc.pb.go b/health/grpc_health_v1/health_grpc.pb.go index 28cd72ea63c0..19b9a06536f5 100644 --- a/health/grpc_health_v1/health_grpc.pb.go +++ b/health/grpc_health_v1/health_grpc.pb.go @@ -88,6 +88,8 @@ func (x *healthWatchClient) Recv() (*HealthCheckResponse, error) { } // HealthServer is the server API for Health service. +// All implementations must embed UnimplementedHealthServer +// for forward compatibility type HealthServer interface { // If the requested service is unknown, the call will fail with status // NOT_FOUND. @@ -108,9 +110,10 @@ type HealthServer interface { // call. If the call terminates with any other status (including OK), // clients should retry the call with appropriate exponential backoff. Watch(*HealthCheckRequest, Health_WatchServer) error + _unimplementedHealthServer() } -// UnimplementedHealthServer can be embedded to have forward compatible implementations. +// UnimplementedHealthServer must be embedded to have forward compatible implementations. type UnimplementedHealthServer struct { } @@ -120,6 +123,7 @@ func (*UnimplementedHealthServer) Check(context.Context, *HealthCheckRequest) (* func (*UnimplementedHealthServer) Watch(*HealthCheckRequest, Health_WatchServer) error { return status.Errorf(codes.Unimplemented, "method Watch not implemented") } +func (*UnimplementedHealthServer) _unimplementedHealthServer() {} func RegisterHealthServer(s *grpc.Server, srv HealthServer) { s.RegisterService(&_Health_serviceDesc, srv) diff --git a/health/server.go b/health/server.go index 6b65124242b8..ed2b3df70f4e 100644 --- a/health/server.go +++ b/health/server.go @@ -33,6 +33,7 @@ import ( // Server implements `service Health`. type Server struct { + healthgrpc.UnimplementedHealthServer mu sync.RWMutex // If shutdown is true, it's expected all serving status is NOT_SERVING, and // will stay in NOT_SERVING. diff --git a/interop/fake_grpclb/fake_grpclb.go b/interop/fake_grpclb/fake_grpclb.go index f6d55045ee22..3b2177ef0291 100644 --- a/interop/fake_grpclb/fake_grpclb.go +++ b/interop/fake_grpclb/fake_grpclb.go @@ -48,6 +48,7 @@ var ( ) type loadBalancerServer struct { + lbpb.UnimplementedLoadBalancerServer serverListResponse *lbpb.LoadBalanceResponse } diff --git a/interop/grpc_testing/test_grpc.pb.go b/interop/grpc_testing/test_grpc.pb.go index d731f4643ecd..cf15e5bd1548 100644 --- a/interop/grpc_testing/test_grpc.pb.go +++ b/interop/grpc_testing/test_grpc.pb.go @@ -194,6 +194,8 @@ func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, } // TestServiceServer is the server API for TestService service. +// All implementations must embed UnimplementedTestServiceServer +// for forward compatibility type TestServiceServer interface { // One empty request followed by one empty response. EmptyCall(context.Context, *Empty) (*Empty, error) @@ -215,9 +217,10 @@ type TestServiceServer interface { // stream of responses are returned to the client when the server starts with // first request. HalfDuplexCall(TestService_HalfDuplexCallServer) error + _unimplementedTestServiceServer() } -// UnimplementedTestServiceServer can be embedded to have forward compatible implementations. +// UnimplementedTestServiceServer must be embedded to have forward compatible implementations. type UnimplementedTestServiceServer struct { } @@ -239,6 +242,7 @@ func (*UnimplementedTestServiceServer) FullDuplexCall(TestService_FullDuplexCall func (*UnimplementedTestServiceServer) HalfDuplexCall(TestService_HalfDuplexCallServer) error { return status.Errorf(codes.Unimplemented, "method HalfDuplexCall not implemented") } +func (*UnimplementedTestServiceServer) _unimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) @@ -445,18 +449,22 @@ func (c *unimplementedServiceClient) UnimplementedCall(ctx context.Context, in * } // UnimplementedServiceServer is the server API for UnimplementedService service. +// All implementations must embed UnimplementedUnimplementedServiceServer +// for forward compatibility type UnimplementedServiceServer interface { // A call that no server should implement UnimplementedCall(context.Context, *Empty) (*Empty, error) + _unimplementedUnimplementedServiceServer() } -// UnimplementedUnimplementedServiceServer can be embedded to have forward compatible implementations. +// UnimplementedUnimplementedServiceServer must be embedded to have forward compatible implementations. type UnimplementedUnimplementedServiceServer struct { } func (*UnimplementedUnimplementedServiceServer) UnimplementedCall(context.Context, *Empty) (*Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method UnimplementedCall not implemented") } +func (*UnimplementedUnimplementedServiceServer) _unimplementedUnimplementedServiceServer() {} func RegisterUnimplementedServiceServer(s *grpc.Server, srv UnimplementedServiceServer) { s.RegisterService(&_UnimplementedService_serviceDesc, srv) @@ -519,18 +527,22 @@ func (c *loadBalancerStatsServiceClient) GetClientStats(ctx context.Context, in } // LoadBalancerStatsServiceServer is the server API for LoadBalancerStatsService service. +// All implementations must embed UnimplementedLoadBalancerStatsServiceServer +// for forward compatibility type LoadBalancerStatsServiceServer interface { // Gets the backend distribution for RPCs sent by a test client. GetClientStats(context.Context, *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) + _unimplementedLoadBalancerStatsServiceServer() } -// UnimplementedLoadBalancerStatsServiceServer can be embedded to have forward compatible implementations. +// UnimplementedLoadBalancerStatsServiceServer must be embedded to have forward compatible implementations. type UnimplementedLoadBalancerStatsServiceServer struct { } func (*UnimplementedLoadBalancerStatsServiceServer) GetClientStats(context.Context, *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetClientStats not implemented") } +func (*UnimplementedLoadBalancerStatsServiceServer) _unimplementedLoadBalancerStatsServiceServer() {} func RegisterLoadBalancerStatsServiceServer(s *grpc.Server, srv LoadBalancerStatsServiceServer) { s.RegisterService(&_LoadBalancerStatsService_serviceDesc, srv) diff --git a/interop/test_utils.go b/interop/test_utils.go index 63ba6a5ebd0a..74e839031881 100644 --- a/interop/test_utils.go +++ b/interop/test_utils.go @@ -672,6 +672,7 @@ func DoPickFirstUnary(tc testpb.TestServiceClient) { } type testServer struct { + testpb.UnimplementedTestServiceServer } // NewTestServer creates a test server for test service. diff --git a/interop/xds/client/client.go b/interop/xds/client/client.go index 009ad26f9d60..44fbf1e6dbb3 100644 --- a/interop/xds/client/client.go +++ b/interop/xds/client/client.go @@ -60,7 +60,9 @@ var ( watchers = make(map[statsWatcherKey]*statsWatcher) ) -type statsService struct{} +type statsService struct { + testpb.UnimplementedLoadBalancerStatsServiceServer +} // Wait for the next LoadBalancerStatsRequest.GetNumRpcs to start and complete, // and return the distribution of remote peers. This is essentially a clientside diff --git a/profiling/proto/service_grpc.pb.go b/profiling/proto/service_grpc.pb.go index 87f1b74b7d06..44250ff4f87e 100644 --- a/profiling/proto/service_grpc.pb.go +++ b/profiling/proto/service_grpc.pb.go @@ -51,15 +51,18 @@ func (c *profilingClient) GetStreamStats(ctx context.Context, in *GetStreamStats } // ProfilingServer is the server API for Profiling service. +// All implementations must embed UnimplementedProfilingServer +// for forward compatibility type ProfilingServer interface { // Enable allows users to toggle profiling on and off remotely. Enable(context.Context, *EnableRequest) (*EnableResponse, error) // GetStreamStats is used to retrieve an array of stream-level stats from a // gRPC client/server. GetStreamStats(context.Context, *GetStreamStatsRequest) (*GetStreamStatsResponse, error) + _unimplementedProfilingServer() } -// UnimplementedProfilingServer can be embedded to have forward compatible implementations. +// UnimplementedProfilingServer must be embedded to have forward compatible implementations. type UnimplementedProfilingServer struct { } @@ -69,6 +72,7 @@ func (*UnimplementedProfilingServer) Enable(context.Context, *EnableRequest) (*E func (*UnimplementedProfilingServer) GetStreamStats(context.Context, *GetStreamStatsRequest) (*GetStreamStatsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetStreamStats not implemented") } +func (*UnimplementedProfilingServer) _unimplementedProfilingServer() {} func RegisterProfilingServer(s *grpc.Server, srv ProfilingServer) { s.RegisterService(&_Profiling_serviceDesc, srv) diff --git a/profiling/service/service.go b/profiling/service/service.go index a36b8bdda883..52a7ce789717 100644 --- a/profiling/service/service.go +++ b/profiling/service/service.go @@ -76,6 +76,7 @@ func Init(pc *ProfilingConfig) error { } type profilingServer struct { + ppb.UnimplementedProfilingServer drainMutex sync.Mutex } diff --git a/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go b/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go index f04e2d4bb0f6..87663dcc3321 100644 --- a/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go +++ b/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go @@ -62,19 +62,23 @@ func (x *serverReflectionServerReflectionInfoClient) Recv() (*ServerReflectionRe } // ServerReflectionServer is the server API for ServerReflection service. +// All implementations must embed UnimplementedServerReflectionServer +// for forward compatibility type ServerReflectionServer interface { // The reflection service is structured as a bidirectional stream, ensuring // all related requests go to a single server. ServerReflectionInfo(ServerReflection_ServerReflectionInfoServer) error + _unimplementedServerReflectionServer() } -// UnimplementedServerReflectionServer can be embedded to have forward compatible implementations. +// UnimplementedServerReflectionServer must be embedded to have forward compatible implementations. type UnimplementedServerReflectionServer struct { } func (*UnimplementedServerReflectionServer) ServerReflectionInfo(ServerReflection_ServerReflectionInfoServer) error { return status.Errorf(codes.Unimplemented, "method ServerReflectionInfo not implemented") } +func (*UnimplementedServerReflectionServer) _unimplementedServerReflectionServer() {} func RegisterServerReflectionServer(s *grpc.Server, srv ServerReflectionServer) { s.RegisterService(&_ServerReflection_serviceDesc, srv) diff --git a/reflection/grpc_testing/test_grpc.pb.go b/reflection/grpc_testing/test_grpc.pb.go index 52eac202bfeb..27dcbe8498f4 100644 --- a/reflection/grpc_testing/test_grpc.pb.go +++ b/reflection/grpc_testing/test_grpc.pb.go @@ -70,12 +70,15 @@ func (x *searchServiceStreamingSearchClient) Recv() (*SearchResponse, error) { } // SearchServiceServer is the server API for SearchService service. +// All implementations must embed UnimplementedSearchServiceServer +// for forward compatibility type SearchServiceServer interface { Search(context.Context, *SearchRequest) (*SearchResponse, error) StreamingSearch(SearchService_StreamingSearchServer) error + _unimplementedSearchServiceServer() } -// UnimplementedSearchServiceServer can be embedded to have forward compatible implementations. +// UnimplementedSearchServiceServer must be embedded to have forward compatible implementations. type UnimplementedSearchServiceServer struct { } @@ -85,6 +88,7 @@ func (*UnimplementedSearchServiceServer) Search(context.Context, *SearchRequest) func (*UnimplementedSearchServiceServer) StreamingSearch(SearchService_StreamingSearchServer) error { return status.Errorf(codes.Unimplemented, "method StreamingSearch not implemented") } +func (*UnimplementedSearchServiceServer) _unimplementedSearchServiceServer() {} func RegisterSearchServiceServer(s *grpc.Server, srv SearchServiceServer) { s.RegisterService(&_SearchService_serviceDesc, srv) diff --git a/reflection/serverreflection.go b/reflection/serverreflection.go index de3e132f0451..7b6dd414a275 100644 --- a/reflection/serverreflection.go +++ b/reflection/serverreflection.go @@ -55,6 +55,7 @@ import ( ) type serverReflectionServer struct { + rpb.UnimplementedServerReflectionServer s *grpc.Server initSymbols sync.Once diff --git a/stats/grpc_testing/test_grpc.pb.go b/stats/grpc_testing/test_grpc.pb.go index a12bccebcfdf..628c6fae7068 100644 --- a/stats/grpc_testing/test_grpc.pb.go +++ b/stats/grpc_testing/test_grpc.pb.go @@ -145,6 +145,8 @@ func (x *testServiceServerStreamCallClient) Recv() (*SimpleResponse, error) { } // TestServiceServer is the server API for TestService service. +// All implementations must embed UnimplementedTestServiceServer +// for forward compatibility type TestServiceServer interface { // One request followed by one response. // The server returns the client id as-is. @@ -157,9 +159,10 @@ type TestServiceServer interface { ClientStreamCall(TestService_ClientStreamCallServer) error // Server stream ServerStreamCall(*SimpleRequest, TestService_ServerStreamCallServer) error + _unimplementedTestServiceServer() } -// UnimplementedTestServiceServer can be embedded to have forward compatible implementations. +// UnimplementedTestServiceServer must be embedded to have forward compatible implementations. type UnimplementedTestServiceServer struct { } @@ -175,6 +178,7 @@ func (*UnimplementedTestServiceServer) ClientStreamCall(TestService_ClientStream func (*UnimplementedTestServiceServer) ServerStreamCall(*SimpleRequest, TestService_ServerStreamCallServer) error { return status.Errorf(codes.Unimplemented, "method ServerStreamCall not implemented") } +func (*UnimplementedTestServiceServer) _unimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) diff --git a/stress/client/main.go b/stress/client/main.go index 86d7539ae7f1..b8f2229a5b76 100644 --- a/stress/client/main.go +++ b/stress/client/main.go @@ -144,6 +144,7 @@ func (g *gauge) get() int64 { // server implements metrics server functions. type server struct { + metricspb.UnimplementedMetricsServiceServer mutex sync.RWMutex // gauges is a map from /stress_test/server_/channel_/stub_/qps to its qps gauge. gauges map[string]*gauge diff --git a/stress/grpc_testing/metrics_grpc.pb.go b/stress/grpc_testing/metrics_grpc.pb.go index 06c8a6b5fa10..768dd1ba408c 100644 --- a/stress/grpc_testing/metrics_grpc.pb.go +++ b/stress/grpc_testing/metrics_grpc.pb.go @@ -74,15 +74,18 @@ func (c *metricsServiceClient) GetGauge(ctx context.Context, in *GaugeRequest, o } // MetricsServiceServer is the server API for MetricsService service. +// All implementations must embed UnimplementedMetricsServiceServer +// for forward compatibility type MetricsServiceServer interface { // Returns the values of all the gauges that are currently being maintained by // the service GetAllGauges(*EmptyMessage, MetricsService_GetAllGaugesServer) error // Returns the value of one gauge GetGauge(context.Context, *GaugeRequest) (*GaugeResponse, error) + _unimplementedMetricsServiceServer() } -// UnimplementedMetricsServiceServer can be embedded to have forward compatible implementations. +// UnimplementedMetricsServiceServer must be embedded to have forward compatible implementations. type UnimplementedMetricsServiceServer struct { } @@ -92,6 +95,7 @@ func (*UnimplementedMetricsServiceServer) GetAllGauges(*EmptyMessage, MetricsSer func (*UnimplementedMetricsServiceServer) GetGauge(context.Context, *GaugeRequest) (*GaugeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetGauge not implemented") } +func (*UnimplementedMetricsServiceServer) _unimplementedMetricsServiceServer() {} func RegisterMetricsServiceServer(s *grpc.Server, srv MetricsServiceServer) { s.RegisterService(&_MetricsService_serviceDesc, srv) diff --git a/test/grpc_testing/test_grpc.pb.go b/test/grpc_testing/test_grpc.pb.go index a211dcab9f35..31d4967ffc4b 100644 --- a/test/grpc_testing/test_grpc.pb.go +++ b/test/grpc_testing/test_grpc.pb.go @@ -194,6 +194,8 @@ func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, } // TestServiceServer is the server API for TestService service. +// All implementations must embed UnimplementedTestServiceServer +// for forward compatibility type TestServiceServer interface { // One empty request followed by one empty response. EmptyCall(context.Context, *Empty) (*Empty, error) @@ -215,9 +217,10 @@ type TestServiceServer interface { // stream of responses are returned to the client when the server starts with // first request. HalfDuplexCall(TestService_HalfDuplexCallServer) error + _unimplementedTestServiceServer() } -// UnimplementedTestServiceServer can be embedded to have forward compatible implementations. +// UnimplementedTestServiceServer must be embedded to have forward compatible implementations. type UnimplementedTestServiceServer struct { } @@ -239,6 +242,7 @@ func (*UnimplementedTestServiceServer) FullDuplexCall(TestService_FullDuplexCall func (*UnimplementedTestServiceServer) HalfDuplexCall(TestService_HalfDuplexCallServer) error { return status.Errorf(codes.Unimplemented, "method HalfDuplexCall not implemented") } +func (*UnimplementedTestServiceServer) _unimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) From 191ebb63f97be5d48887dd3c8f87289272e0c562 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Mon, 1 Jun 2020 17:00:56 -0700 Subject: [PATCH 2/8] remove the _ --- cmd/protoc-gen-go-grpc/grpc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/protoc-gen-go-grpc/grpc.go b/cmd/protoc-gen-go-grpc/grpc.go index 7db8597b4d53..325b78d4ce16 100644 --- a/cmd/protoc-gen-go-grpc/grpc.go +++ b/cmd/protoc-gen-go-grpc/grpc.go @@ -139,7 +139,7 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated serverSignature(g, method)) } if *requireUnimplemented { - g.P("_unimplemented", serverType, "()") + g.P("unimplemented", serverType, "()") } g.P("}") g.P() @@ -158,7 +158,7 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P("return ", nilArg, statusPackage.Ident("Errorf"), "(", codesPackage.Ident("Unimplemented"), `, "method `, method.GoName, ` not implemented")`) g.P("}") } - g.P("func (*Unimplemented", serverType, ") _unimplemented", serverType, "() {}") + g.P("func (*Unimplemented", serverType, ") unimplemented", serverType, "() {}") g.P() // Server registration. From c14716d857c4bc6ffa6ca64cd43244ac4809d34e Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Mon, 1 Jun 2020 17:01:12 -0700 Subject: [PATCH 3/8] regenerate --- balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go | 4 ++-- .../rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go | 4 ++-- benchmark/grpc_testing/services_grpc.pb.go | 8 ++++---- channelz/grpc_channelz_v1/channelz_grpc.pb.go | 4 ++-- .../internal/proto/grpc_gcp/handshaker_grpc.pb.go | 4 ++-- examples/features/proto/echo/echo_grpc.pb.go | 4 ++-- examples/helloworld/helloworld/helloworld_grpc.pb.go | 4 ++-- .../route_guide/routeguide/route_guide_grpc.pb.go | 4 ++-- health/grpc_health_v1/health_grpc.pb.go | 4 ++-- interop/grpc_testing/test_grpc.pb.go | 12 ++++++------ profiling/proto/service_grpc.pb.go | 4 ++-- .../grpc_reflection_v1alpha/reflection_grpc.pb.go | 4 ++-- reflection/grpc_testing/test_grpc.pb.go | 4 ++-- stats/grpc_testing/test_grpc.pb.go | 4 ++-- stress/grpc_testing/metrics_grpc.pb.go | 4 ++-- test/grpc_testing/test_grpc.pb.go | 4 ++-- 16 files changed, 38 insertions(+), 38 deletions(-) diff --git a/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go b/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go index ed0d9c1d4d2b..cf2e0099d7e3 100644 --- a/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go +++ b/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go @@ -66,7 +66,7 @@ func (x *loadBalancerBalanceLoadClient) Recv() (*LoadBalanceResponse, error) { type LoadBalancerServer interface { // Bidirectional rpc to get a list of servers. BalanceLoad(LoadBalancer_BalanceLoadServer) error - _unimplementedLoadBalancerServer() + unimplementedLoadBalancerServer() } // UnimplementedLoadBalancerServer must be embedded to have forward compatible implementations. @@ -76,7 +76,7 @@ type UnimplementedLoadBalancerServer struct { func (*UnimplementedLoadBalancerServer) BalanceLoad(LoadBalancer_BalanceLoadServer) error { return status.Errorf(codes.Unimplemented, "method BalanceLoad not implemented") } -func (*UnimplementedLoadBalancerServer) _unimplementedLoadBalancerServer() {} +func (*UnimplementedLoadBalancerServer) unimplementedLoadBalancerServer() {} func RegisterLoadBalancerServer(s *grpc.Server, srv LoadBalancerServer) { s.RegisterService(&_LoadBalancer_serviceDesc, srv) diff --git a/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go b/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go index 7a1fb41e937d..ee7dc726c8dd 100644 --- a/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go +++ b/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go @@ -44,7 +44,7 @@ func (c *routeLookupServiceClient) RouteLookup(ctx context.Context, in *RouteLoo type RouteLookupServiceServer interface { // Lookup returns a target for a single key. RouteLookup(context.Context, *RouteLookupRequest) (*RouteLookupResponse, error) - _unimplementedRouteLookupServiceServer() + unimplementedRouteLookupServiceServer() } // UnimplementedRouteLookupServiceServer must be embedded to have forward compatible implementations. @@ -54,7 +54,7 @@ type UnimplementedRouteLookupServiceServer struct { func (*UnimplementedRouteLookupServiceServer) RouteLookup(context.Context, *RouteLookupRequest) (*RouteLookupResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RouteLookup not implemented") } -func (*UnimplementedRouteLookupServiceServer) _unimplementedRouteLookupServiceServer() {} +func (*UnimplementedRouteLookupServiceServer) unimplementedRouteLookupServiceServer() {} func RegisterRouteLookupServiceServer(s *grpc.Server, srv RouteLookupServiceServer) { s.RegisterService(&_RouteLookupService_serviceDesc, srv) diff --git a/benchmark/grpc_testing/services_grpc.pb.go b/benchmark/grpc_testing/services_grpc.pb.go index 6e08399fb990..7cb1e8a509c5 100644 --- a/benchmark/grpc_testing/services_grpc.pb.go +++ b/benchmark/grpc_testing/services_grpc.pb.go @@ -120,7 +120,7 @@ type BenchmarkServiceServer interface { // Unconstrainted streaming. // Both server and client keep sending & receiving simultaneously. UnconstrainedStreamingCall(BenchmarkService_UnconstrainedStreamingCallServer) error - _unimplementedBenchmarkServiceServer() + unimplementedBenchmarkServiceServer() } // UnimplementedBenchmarkServiceServer must be embedded to have forward compatible implementations. @@ -136,7 +136,7 @@ func (*UnimplementedBenchmarkServiceServer) StreamingCall(BenchmarkService_Strea func (*UnimplementedBenchmarkServiceServer) UnconstrainedStreamingCall(BenchmarkService_UnconstrainedStreamingCallServer) error { return status.Errorf(codes.Unimplemented, "method UnconstrainedStreamingCall not implemented") } -func (*UnimplementedBenchmarkServiceServer) _unimplementedBenchmarkServiceServer() {} +func (*UnimplementedBenchmarkServiceServer) unimplementedBenchmarkServiceServer() {} func RegisterBenchmarkServiceServer(s *grpc.Server, srv BenchmarkServiceServer) { s.RegisterService(&_BenchmarkService_serviceDesc, srv) @@ -372,7 +372,7 @@ type WorkerServiceServer interface { CoreCount(context.Context, *CoreRequest) (*CoreResponse, error) // Quit this worker QuitWorker(context.Context, *Void) (*Void, error) - _unimplementedWorkerServiceServer() + unimplementedWorkerServiceServer() } // UnimplementedWorkerServiceServer must be embedded to have forward compatible implementations. @@ -391,7 +391,7 @@ func (*UnimplementedWorkerServiceServer) CoreCount(context.Context, *CoreRequest func (*UnimplementedWorkerServiceServer) QuitWorker(context.Context, *Void) (*Void, error) { return nil, status.Errorf(codes.Unimplemented, "method QuitWorker not implemented") } -func (*UnimplementedWorkerServiceServer) _unimplementedWorkerServiceServer() {} +func (*UnimplementedWorkerServiceServer) unimplementedWorkerServiceServer() {} func RegisterWorkerServiceServer(s *grpc.Server, srv WorkerServiceServer) { s.RegisterService(&_WorkerService_serviceDesc, srv) diff --git a/channelz/grpc_channelz_v1/channelz_grpc.pb.go b/channelz/grpc_channelz_v1/channelz_grpc.pb.go index d96668ac8707..36a56576dd50 100644 --- a/channelz/grpc_channelz_v1/channelz_grpc.pb.go +++ b/channelz/grpc_channelz_v1/channelz_grpc.pb.go @@ -124,7 +124,7 @@ type ChannelzServer interface { GetSubchannel(context.Context, *GetSubchannelRequest) (*GetSubchannelResponse, error) // Returns a single Socket or else a NOT_FOUND code. GetSocket(context.Context, *GetSocketRequest) (*GetSocketResponse, error) - _unimplementedChannelzServer() + unimplementedChannelzServer() } // UnimplementedChannelzServer must be embedded to have forward compatible implementations. @@ -152,7 +152,7 @@ func (*UnimplementedChannelzServer) GetSubchannel(context.Context, *GetSubchanne func (*UnimplementedChannelzServer) GetSocket(context.Context, *GetSocketRequest) (*GetSocketResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetSocket not implemented") } -func (*UnimplementedChannelzServer) _unimplementedChannelzServer() {} +func (*UnimplementedChannelzServer) unimplementedChannelzServer() {} func RegisterChannelzServer(s *grpc.Server, srv ChannelzServer) { s.RegisterService(&_Channelz_serviceDesc, srv) diff --git a/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go b/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go index 3809a101a4cd..658a80525f3d 100644 --- a/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go +++ b/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go @@ -76,7 +76,7 @@ type HandshakerServiceServer interface { // service expects to respond. Client does not have to wait for service's // response before sending next request. DoHandshake(HandshakerService_DoHandshakeServer) error - _unimplementedHandshakerServiceServer() + unimplementedHandshakerServiceServer() } // UnimplementedHandshakerServiceServer must be embedded to have forward compatible implementations. @@ -86,7 +86,7 @@ type UnimplementedHandshakerServiceServer struct { func (*UnimplementedHandshakerServiceServer) DoHandshake(HandshakerService_DoHandshakeServer) error { return status.Errorf(codes.Unimplemented, "method DoHandshake not implemented") } -func (*UnimplementedHandshakerServiceServer) _unimplementedHandshakerServiceServer() {} +func (*UnimplementedHandshakerServiceServer) unimplementedHandshakerServiceServer() {} func RegisterHandshakerServiceServer(s *grpc.Server, srv HandshakerServiceServer) { s.RegisterService(&_HandshakerService_serviceDesc, srv) diff --git a/examples/features/proto/echo/echo_grpc.pb.go b/examples/features/proto/echo/echo_grpc.pb.go index b5308262e80a..4a697db6dd1c 100644 --- a/examples/features/proto/echo/echo_grpc.pb.go +++ b/examples/features/proto/echo/echo_grpc.pb.go @@ -153,7 +153,7 @@ type EchoServer interface { ClientStreamingEcho(Echo_ClientStreamingEchoServer) error // BidirectionalStreamingEcho is bidi streaming. BidirectionalStreamingEcho(Echo_BidirectionalStreamingEchoServer) error - _unimplementedEchoServer() + unimplementedEchoServer() } // UnimplementedEchoServer must be embedded to have forward compatible implementations. @@ -172,7 +172,7 @@ func (*UnimplementedEchoServer) ClientStreamingEcho(Echo_ClientStreamingEchoServ func (*UnimplementedEchoServer) BidirectionalStreamingEcho(Echo_BidirectionalStreamingEchoServer) error { return status.Errorf(codes.Unimplemented, "method BidirectionalStreamingEcho not implemented") } -func (*UnimplementedEchoServer) _unimplementedEchoServer() {} +func (*UnimplementedEchoServer) unimplementedEchoServer() {} func RegisterEchoServer(s *grpc.Server, srv EchoServer) { s.RegisterService(&_Echo_serviceDesc, srv) diff --git a/examples/helloworld/helloworld/helloworld_grpc.pb.go b/examples/helloworld/helloworld/helloworld_grpc.pb.go index 0d5b27e19c6e..8bc9ad87922a 100644 --- a/examples/helloworld/helloworld/helloworld_grpc.pb.go +++ b/examples/helloworld/helloworld/helloworld_grpc.pb.go @@ -44,7 +44,7 @@ func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ... type GreeterServer interface { // Sends a greeting SayHello(context.Context, *HelloRequest) (*HelloReply, error) - _unimplementedGreeterServer() + unimplementedGreeterServer() } // UnimplementedGreeterServer must be embedded to have forward compatible implementations. @@ -54,7 +54,7 @@ type UnimplementedGreeterServer struct { func (*UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } -func (*UnimplementedGreeterServer) _unimplementedGreeterServer() {} +func (*UnimplementedGreeterServer) unimplementedGreeterServer() {} func RegisterGreeterServer(s *grpc.Server, srv GreeterServer) { s.RegisterService(&_Greeter_serviceDesc, srv) diff --git a/examples/route_guide/routeguide/route_guide_grpc.pb.go b/examples/route_guide/routeguide/route_guide_grpc.pb.go index e2a74cf0bbd9..76b43c66b7e1 100644 --- a/examples/route_guide/routeguide/route_guide_grpc.pb.go +++ b/examples/route_guide/routeguide/route_guide_grpc.pb.go @@ -185,7 +185,7 @@ type RouteGuideServer interface { // Accepts a stream of RouteNotes sent while a route is being traversed, // while receiving other RouteNotes (e.g. from other users). RouteChat(RouteGuide_RouteChatServer) error - _unimplementedRouteGuideServer() + unimplementedRouteGuideServer() } // UnimplementedRouteGuideServer must be embedded to have forward compatible implementations. @@ -204,7 +204,7 @@ func (*UnimplementedRouteGuideServer) RecordRoute(RouteGuide_RecordRouteServer) func (*UnimplementedRouteGuideServer) RouteChat(RouteGuide_RouteChatServer) error { return status.Errorf(codes.Unimplemented, "method RouteChat not implemented") } -func (*UnimplementedRouteGuideServer) _unimplementedRouteGuideServer() {} +func (*UnimplementedRouteGuideServer) unimplementedRouteGuideServer() {} func RegisterRouteGuideServer(s *grpc.Server, srv RouteGuideServer) { s.RegisterService(&_RouteGuide_serviceDesc, srv) diff --git a/health/grpc_health_v1/health_grpc.pb.go b/health/grpc_health_v1/health_grpc.pb.go index 19b9a06536f5..b469f5de965b 100644 --- a/health/grpc_health_v1/health_grpc.pb.go +++ b/health/grpc_health_v1/health_grpc.pb.go @@ -110,7 +110,7 @@ type HealthServer interface { // call. If the call terminates with any other status (including OK), // clients should retry the call with appropriate exponential backoff. Watch(*HealthCheckRequest, Health_WatchServer) error - _unimplementedHealthServer() + unimplementedHealthServer() } // UnimplementedHealthServer must be embedded to have forward compatible implementations. @@ -123,7 +123,7 @@ func (*UnimplementedHealthServer) Check(context.Context, *HealthCheckRequest) (* func (*UnimplementedHealthServer) Watch(*HealthCheckRequest, Health_WatchServer) error { return status.Errorf(codes.Unimplemented, "method Watch not implemented") } -func (*UnimplementedHealthServer) _unimplementedHealthServer() {} +func (*UnimplementedHealthServer) unimplementedHealthServer() {} func RegisterHealthServer(s *grpc.Server, srv HealthServer) { s.RegisterService(&_Health_serviceDesc, srv) diff --git a/interop/grpc_testing/test_grpc.pb.go b/interop/grpc_testing/test_grpc.pb.go index cf15e5bd1548..bfd05d8eb0c9 100644 --- a/interop/grpc_testing/test_grpc.pb.go +++ b/interop/grpc_testing/test_grpc.pb.go @@ -217,7 +217,7 @@ type TestServiceServer interface { // stream of responses are returned to the client when the server starts with // first request. HalfDuplexCall(TestService_HalfDuplexCallServer) error - _unimplementedTestServiceServer() + unimplementedTestServiceServer() } // UnimplementedTestServiceServer must be embedded to have forward compatible implementations. @@ -242,7 +242,7 @@ func (*UnimplementedTestServiceServer) FullDuplexCall(TestService_FullDuplexCall func (*UnimplementedTestServiceServer) HalfDuplexCall(TestService_HalfDuplexCallServer) error { return status.Errorf(codes.Unimplemented, "method HalfDuplexCall not implemented") } -func (*UnimplementedTestServiceServer) _unimplementedTestServiceServer() {} +func (*UnimplementedTestServiceServer) unimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) @@ -454,7 +454,7 @@ func (c *unimplementedServiceClient) UnimplementedCall(ctx context.Context, in * type UnimplementedServiceServer interface { // A call that no server should implement UnimplementedCall(context.Context, *Empty) (*Empty, error) - _unimplementedUnimplementedServiceServer() + unimplementedUnimplementedServiceServer() } // UnimplementedUnimplementedServiceServer must be embedded to have forward compatible implementations. @@ -464,7 +464,7 @@ type UnimplementedUnimplementedServiceServer struct { func (*UnimplementedUnimplementedServiceServer) UnimplementedCall(context.Context, *Empty) (*Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method UnimplementedCall not implemented") } -func (*UnimplementedUnimplementedServiceServer) _unimplementedUnimplementedServiceServer() {} +func (*UnimplementedUnimplementedServiceServer) unimplementedUnimplementedServiceServer() {} func RegisterUnimplementedServiceServer(s *grpc.Server, srv UnimplementedServiceServer) { s.RegisterService(&_UnimplementedService_serviceDesc, srv) @@ -532,7 +532,7 @@ func (c *loadBalancerStatsServiceClient) GetClientStats(ctx context.Context, in type LoadBalancerStatsServiceServer interface { // Gets the backend distribution for RPCs sent by a test client. GetClientStats(context.Context, *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) - _unimplementedLoadBalancerStatsServiceServer() + unimplementedLoadBalancerStatsServiceServer() } // UnimplementedLoadBalancerStatsServiceServer must be embedded to have forward compatible implementations. @@ -542,7 +542,7 @@ type UnimplementedLoadBalancerStatsServiceServer struct { func (*UnimplementedLoadBalancerStatsServiceServer) GetClientStats(context.Context, *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetClientStats not implemented") } -func (*UnimplementedLoadBalancerStatsServiceServer) _unimplementedLoadBalancerStatsServiceServer() {} +func (*UnimplementedLoadBalancerStatsServiceServer) unimplementedLoadBalancerStatsServiceServer() {} func RegisterLoadBalancerStatsServiceServer(s *grpc.Server, srv LoadBalancerStatsServiceServer) { s.RegisterService(&_LoadBalancerStatsService_serviceDesc, srv) diff --git a/profiling/proto/service_grpc.pb.go b/profiling/proto/service_grpc.pb.go index 44250ff4f87e..bcf555305388 100644 --- a/profiling/proto/service_grpc.pb.go +++ b/profiling/proto/service_grpc.pb.go @@ -59,7 +59,7 @@ type ProfilingServer interface { // GetStreamStats is used to retrieve an array of stream-level stats from a // gRPC client/server. GetStreamStats(context.Context, *GetStreamStatsRequest) (*GetStreamStatsResponse, error) - _unimplementedProfilingServer() + unimplementedProfilingServer() } // UnimplementedProfilingServer must be embedded to have forward compatible implementations. @@ -72,7 +72,7 @@ func (*UnimplementedProfilingServer) Enable(context.Context, *EnableRequest) (*E func (*UnimplementedProfilingServer) GetStreamStats(context.Context, *GetStreamStatsRequest) (*GetStreamStatsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetStreamStats not implemented") } -func (*UnimplementedProfilingServer) _unimplementedProfilingServer() {} +func (*UnimplementedProfilingServer) unimplementedProfilingServer() {} func RegisterProfilingServer(s *grpc.Server, srv ProfilingServer) { s.RegisterService(&_Profiling_serviceDesc, srv) diff --git a/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go b/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go index 87663dcc3321..f868330365af 100644 --- a/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go +++ b/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go @@ -68,7 +68,7 @@ type ServerReflectionServer interface { // The reflection service is structured as a bidirectional stream, ensuring // all related requests go to a single server. ServerReflectionInfo(ServerReflection_ServerReflectionInfoServer) error - _unimplementedServerReflectionServer() + unimplementedServerReflectionServer() } // UnimplementedServerReflectionServer must be embedded to have forward compatible implementations. @@ -78,7 +78,7 @@ type UnimplementedServerReflectionServer struct { func (*UnimplementedServerReflectionServer) ServerReflectionInfo(ServerReflection_ServerReflectionInfoServer) error { return status.Errorf(codes.Unimplemented, "method ServerReflectionInfo not implemented") } -func (*UnimplementedServerReflectionServer) _unimplementedServerReflectionServer() {} +func (*UnimplementedServerReflectionServer) unimplementedServerReflectionServer() {} func RegisterServerReflectionServer(s *grpc.Server, srv ServerReflectionServer) { s.RegisterService(&_ServerReflection_serviceDesc, srv) diff --git a/reflection/grpc_testing/test_grpc.pb.go b/reflection/grpc_testing/test_grpc.pb.go index 27dcbe8498f4..2e4ccd8eca04 100644 --- a/reflection/grpc_testing/test_grpc.pb.go +++ b/reflection/grpc_testing/test_grpc.pb.go @@ -75,7 +75,7 @@ func (x *searchServiceStreamingSearchClient) Recv() (*SearchResponse, error) { type SearchServiceServer interface { Search(context.Context, *SearchRequest) (*SearchResponse, error) StreamingSearch(SearchService_StreamingSearchServer) error - _unimplementedSearchServiceServer() + unimplementedSearchServiceServer() } // UnimplementedSearchServiceServer must be embedded to have forward compatible implementations. @@ -88,7 +88,7 @@ func (*UnimplementedSearchServiceServer) Search(context.Context, *SearchRequest) func (*UnimplementedSearchServiceServer) StreamingSearch(SearchService_StreamingSearchServer) error { return status.Errorf(codes.Unimplemented, "method StreamingSearch not implemented") } -func (*UnimplementedSearchServiceServer) _unimplementedSearchServiceServer() {} +func (*UnimplementedSearchServiceServer) unimplementedSearchServiceServer() {} func RegisterSearchServiceServer(s *grpc.Server, srv SearchServiceServer) { s.RegisterService(&_SearchService_serviceDesc, srv) diff --git a/stats/grpc_testing/test_grpc.pb.go b/stats/grpc_testing/test_grpc.pb.go index 628c6fae7068..3778a3ef33e4 100644 --- a/stats/grpc_testing/test_grpc.pb.go +++ b/stats/grpc_testing/test_grpc.pb.go @@ -159,7 +159,7 @@ type TestServiceServer interface { ClientStreamCall(TestService_ClientStreamCallServer) error // Server stream ServerStreamCall(*SimpleRequest, TestService_ServerStreamCallServer) error - _unimplementedTestServiceServer() + unimplementedTestServiceServer() } // UnimplementedTestServiceServer must be embedded to have forward compatible implementations. @@ -178,7 +178,7 @@ func (*UnimplementedTestServiceServer) ClientStreamCall(TestService_ClientStream func (*UnimplementedTestServiceServer) ServerStreamCall(*SimpleRequest, TestService_ServerStreamCallServer) error { return status.Errorf(codes.Unimplemented, "method ServerStreamCall not implemented") } -func (*UnimplementedTestServiceServer) _unimplementedTestServiceServer() {} +func (*UnimplementedTestServiceServer) unimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) diff --git a/stress/grpc_testing/metrics_grpc.pb.go b/stress/grpc_testing/metrics_grpc.pb.go index 768dd1ba408c..8ca55b26bab7 100644 --- a/stress/grpc_testing/metrics_grpc.pb.go +++ b/stress/grpc_testing/metrics_grpc.pb.go @@ -82,7 +82,7 @@ type MetricsServiceServer interface { GetAllGauges(*EmptyMessage, MetricsService_GetAllGaugesServer) error // Returns the value of one gauge GetGauge(context.Context, *GaugeRequest) (*GaugeResponse, error) - _unimplementedMetricsServiceServer() + unimplementedMetricsServiceServer() } // UnimplementedMetricsServiceServer must be embedded to have forward compatible implementations. @@ -95,7 +95,7 @@ func (*UnimplementedMetricsServiceServer) GetAllGauges(*EmptyMessage, MetricsSer func (*UnimplementedMetricsServiceServer) GetGauge(context.Context, *GaugeRequest) (*GaugeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetGauge not implemented") } -func (*UnimplementedMetricsServiceServer) _unimplementedMetricsServiceServer() {} +func (*UnimplementedMetricsServiceServer) unimplementedMetricsServiceServer() {} func RegisterMetricsServiceServer(s *grpc.Server, srv MetricsServiceServer) { s.RegisterService(&_MetricsService_serviceDesc, srv) diff --git a/test/grpc_testing/test_grpc.pb.go b/test/grpc_testing/test_grpc.pb.go index 31d4967ffc4b..2b93b84118b8 100644 --- a/test/grpc_testing/test_grpc.pb.go +++ b/test/grpc_testing/test_grpc.pb.go @@ -217,7 +217,7 @@ type TestServiceServer interface { // stream of responses are returned to the client when the server starts with // first request. HalfDuplexCall(TestService_HalfDuplexCallServer) error - _unimplementedTestServiceServer() + unimplementedTestServiceServer() } // UnimplementedTestServiceServer must be embedded to have forward compatible implementations. @@ -242,7 +242,7 @@ func (*UnimplementedTestServiceServer) FullDuplexCall(TestService_FullDuplexCall func (*UnimplementedTestServiceServer) HalfDuplexCall(TestService_HalfDuplexCallServer) error { return status.Errorf(codes.Unimplemented, "method HalfDuplexCall not implemented") } -func (*UnimplementedTestServiceServer) _unimplementedTestServiceServer() {} +func (*UnimplementedTestServiceServer) unimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) From 48faafb525d1ed78d84884c938693b2fd8a023d5 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Tue, 2 Jun 2020 10:34:32 -0700 Subject: [PATCH 4/8] mustEmbed --- balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go | 4 ++-- .../internal/proto/grpc_lookup_v1/rls_grpc.pb.go | 4 ++-- benchmark/grpc_testing/services_grpc.pb.go | 8 ++++---- channelz/grpc_channelz_v1/channelz_grpc.pb.go | 4 ++-- cmd/protoc-gen-go-grpc/grpc.go | 4 ++-- .../internal/proto/grpc_gcp/handshaker_grpc.pb.go | 4 ++-- examples/features/proto/echo/echo_grpc.pb.go | 4 ++-- .../helloworld/helloworld/helloworld_grpc.pb.go | 4 ++-- .../route_guide/routeguide/route_guide_grpc.pb.go | 4 ++-- health/grpc_health_v1/health_grpc.pb.go | 4 ++-- interop/grpc_testing/test_grpc.pb.go | 13 +++++++------ profiling/proto/service_grpc.pb.go | 4 ++-- .../grpc_reflection_v1alpha/reflection_grpc.pb.go | 4 ++-- reflection/grpc_testing/test_grpc.pb.go | 4 ++-- stats/grpc_testing/test_grpc.pb.go | 4 ++-- stress/grpc_testing/metrics_grpc.pb.go | 4 ++-- test/grpc_testing/test_grpc.pb.go | 4 ++-- 17 files changed, 41 insertions(+), 40 deletions(-) diff --git a/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go b/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go index cf2e0099d7e3..1477b8e9dcdd 100644 --- a/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go +++ b/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go @@ -66,7 +66,7 @@ func (x *loadBalancerBalanceLoadClient) Recv() (*LoadBalanceResponse, error) { type LoadBalancerServer interface { // Bidirectional rpc to get a list of servers. BalanceLoad(LoadBalancer_BalanceLoadServer) error - unimplementedLoadBalancerServer() + mustEmbedUnimplementedLoadBalancerServer() } // UnimplementedLoadBalancerServer must be embedded to have forward compatible implementations. @@ -76,7 +76,7 @@ type UnimplementedLoadBalancerServer struct { func (*UnimplementedLoadBalancerServer) BalanceLoad(LoadBalancer_BalanceLoadServer) error { return status.Errorf(codes.Unimplemented, "method BalanceLoad not implemented") } -func (*UnimplementedLoadBalancerServer) unimplementedLoadBalancerServer() {} +func (*UnimplementedLoadBalancerServer) mustEmbedUnimplementedLoadBalancerServer() {} func RegisterLoadBalancerServer(s *grpc.Server, srv LoadBalancerServer) { s.RegisterService(&_LoadBalancer_serviceDesc, srv) diff --git a/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go b/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go index ee7dc726c8dd..1a72ddd79825 100644 --- a/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go +++ b/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go @@ -44,7 +44,7 @@ func (c *routeLookupServiceClient) RouteLookup(ctx context.Context, in *RouteLoo type RouteLookupServiceServer interface { // Lookup returns a target for a single key. RouteLookup(context.Context, *RouteLookupRequest) (*RouteLookupResponse, error) - unimplementedRouteLookupServiceServer() + mustEmbedUnimplementedRouteLookupServiceServer() } // UnimplementedRouteLookupServiceServer must be embedded to have forward compatible implementations. @@ -54,7 +54,7 @@ type UnimplementedRouteLookupServiceServer struct { func (*UnimplementedRouteLookupServiceServer) RouteLookup(context.Context, *RouteLookupRequest) (*RouteLookupResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RouteLookup not implemented") } -func (*UnimplementedRouteLookupServiceServer) unimplementedRouteLookupServiceServer() {} +func (*UnimplementedRouteLookupServiceServer) mustEmbedUnimplementedRouteLookupServiceServer() {} func RegisterRouteLookupServiceServer(s *grpc.Server, srv RouteLookupServiceServer) { s.RegisterService(&_RouteLookupService_serviceDesc, srv) diff --git a/benchmark/grpc_testing/services_grpc.pb.go b/benchmark/grpc_testing/services_grpc.pb.go index 7cb1e8a509c5..14b1d796e4be 100644 --- a/benchmark/grpc_testing/services_grpc.pb.go +++ b/benchmark/grpc_testing/services_grpc.pb.go @@ -120,7 +120,7 @@ type BenchmarkServiceServer interface { // Unconstrainted streaming. // Both server and client keep sending & receiving simultaneously. UnconstrainedStreamingCall(BenchmarkService_UnconstrainedStreamingCallServer) error - unimplementedBenchmarkServiceServer() + mustEmbedUnimplementedBenchmarkServiceServer() } // UnimplementedBenchmarkServiceServer must be embedded to have forward compatible implementations. @@ -136,7 +136,7 @@ func (*UnimplementedBenchmarkServiceServer) StreamingCall(BenchmarkService_Strea func (*UnimplementedBenchmarkServiceServer) UnconstrainedStreamingCall(BenchmarkService_UnconstrainedStreamingCallServer) error { return status.Errorf(codes.Unimplemented, "method UnconstrainedStreamingCall not implemented") } -func (*UnimplementedBenchmarkServiceServer) unimplementedBenchmarkServiceServer() {} +func (*UnimplementedBenchmarkServiceServer) mustEmbedUnimplementedBenchmarkServiceServer() {} func RegisterBenchmarkServiceServer(s *grpc.Server, srv BenchmarkServiceServer) { s.RegisterService(&_BenchmarkService_serviceDesc, srv) @@ -372,7 +372,7 @@ type WorkerServiceServer interface { CoreCount(context.Context, *CoreRequest) (*CoreResponse, error) // Quit this worker QuitWorker(context.Context, *Void) (*Void, error) - unimplementedWorkerServiceServer() + mustEmbedUnimplementedWorkerServiceServer() } // UnimplementedWorkerServiceServer must be embedded to have forward compatible implementations. @@ -391,7 +391,7 @@ func (*UnimplementedWorkerServiceServer) CoreCount(context.Context, *CoreRequest func (*UnimplementedWorkerServiceServer) QuitWorker(context.Context, *Void) (*Void, error) { return nil, status.Errorf(codes.Unimplemented, "method QuitWorker not implemented") } -func (*UnimplementedWorkerServiceServer) unimplementedWorkerServiceServer() {} +func (*UnimplementedWorkerServiceServer) mustEmbedUnimplementedWorkerServiceServer() {} func RegisterWorkerServiceServer(s *grpc.Server, srv WorkerServiceServer) { s.RegisterService(&_WorkerService_serviceDesc, srv) diff --git a/channelz/grpc_channelz_v1/channelz_grpc.pb.go b/channelz/grpc_channelz_v1/channelz_grpc.pb.go index 36a56576dd50..6d58844372cb 100644 --- a/channelz/grpc_channelz_v1/channelz_grpc.pb.go +++ b/channelz/grpc_channelz_v1/channelz_grpc.pb.go @@ -124,7 +124,7 @@ type ChannelzServer interface { GetSubchannel(context.Context, *GetSubchannelRequest) (*GetSubchannelResponse, error) // Returns a single Socket or else a NOT_FOUND code. GetSocket(context.Context, *GetSocketRequest) (*GetSocketResponse, error) - unimplementedChannelzServer() + mustEmbedUnimplementedChannelzServer() } // UnimplementedChannelzServer must be embedded to have forward compatible implementations. @@ -152,7 +152,7 @@ func (*UnimplementedChannelzServer) GetSubchannel(context.Context, *GetSubchanne func (*UnimplementedChannelzServer) GetSocket(context.Context, *GetSocketRequest) (*GetSocketResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetSocket not implemented") } -func (*UnimplementedChannelzServer) unimplementedChannelzServer() {} +func (*UnimplementedChannelzServer) mustEmbedUnimplementedChannelzServer() {} func RegisterChannelzServer(s *grpc.Server, srv ChannelzServer) { s.RegisterService(&_Channelz_serviceDesc, srv) diff --git a/cmd/protoc-gen-go-grpc/grpc.go b/cmd/protoc-gen-go-grpc/grpc.go index 325b78d4ce16..008206ff5036 100644 --- a/cmd/protoc-gen-go-grpc/grpc.go +++ b/cmd/protoc-gen-go-grpc/grpc.go @@ -139,7 +139,7 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated serverSignature(g, method)) } if *requireUnimplemented { - g.P("unimplemented", serverType, "()") + g.P("mustEmbedUnimplemented", serverType, "()") } g.P("}") g.P() @@ -158,7 +158,7 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P("return ", nilArg, statusPackage.Ident("Errorf"), "(", codesPackage.Ident("Unimplemented"), `, "method `, method.GoName, ` not implemented")`) g.P("}") } - g.P("func (*Unimplemented", serverType, ") unimplemented", serverType, "() {}") + g.P("func (*Unimplemented", serverType, ") mustEmbedUnimplemented", serverType, "() {}") g.P() // Server registration. diff --git a/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go b/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go index 658a80525f3d..631f66edf13c 100644 --- a/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go +++ b/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go @@ -76,7 +76,7 @@ type HandshakerServiceServer interface { // service expects to respond. Client does not have to wait for service's // response before sending next request. DoHandshake(HandshakerService_DoHandshakeServer) error - unimplementedHandshakerServiceServer() + mustEmbedUnimplementedHandshakerServiceServer() } // UnimplementedHandshakerServiceServer must be embedded to have forward compatible implementations. @@ -86,7 +86,7 @@ type UnimplementedHandshakerServiceServer struct { func (*UnimplementedHandshakerServiceServer) DoHandshake(HandshakerService_DoHandshakeServer) error { return status.Errorf(codes.Unimplemented, "method DoHandshake not implemented") } -func (*UnimplementedHandshakerServiceServer) unimplementedHandshakerServiceServer() {} +func (*UnimplementedHandshakerServiceServer) mustEmbedUnimplementedHandshakerServiceServer() {} func RegisterHandshakerServiceServer(s *grpc.Server, srv HandshakerServiceServer) { s.RegisterService(&_HandshakerService_serviceDesc, srv) diff --git a/examples/features/proto/echo/echo_grpc.pb.go b/examples/features/proto/echo/echo_grpc.pb.go index 4a697db6dd1c..6304d09e7576 100644 --- a/examples/features/proto/echo/echo_grpc.pb.go +++ b/examples/features/proto/echo/echo_grpc.pb.go @@ -153,7 +153,7 @@ type EchoServer interface { ClientStreamingEcho(Echo_ClientStreamingEchoServer) error // BidirectionalStreamingEcho is bidi streaming. BidirectionalStreamingEcho(Echo_BidirectionalStreamingEchoServer) error - unimplementedEchoServer() + mustEmbedUnimplementedEchoServer() } // UnimplementedEchoServer must be embedded to have forward compatible implementations. @@ -172,7 +172,7 @@ func (*UnimplementedEchoServer) ClientStreamingEcho(Echo_ClientStreamingEchoServ func (*UnimplementedEchoServer) BidirectionalStreamingEcho(Echo_BidirectionalStreamingEchoServer) error { return status.Errorf(codes.Unimplemented, "method BidirectionalStreamingEcho not implemented") } -func (*UnimplementedEchoServer) unimplementedEchoServer() {} +func (*UnimplementedEchoServer) mustEmbedUnimplementedEchoServer() {} func RegisterEchoServer(s *grpc.Server, srv EchoServer) { s.RegisterService(&_Echo_serviceDesc, srv) diff --git a/examples/helloworld/helloworld/helloworld_grpc.pb.go b/examples/helloworld/helloworld/helloworld_grpc.pb.go index 8bc9ad87922a..3d48dba48def 100644 --- a/examples/helloworld/helloworld/helloworld_grpc.pb.go +++ b/examples/helloworld/helloworld/helloworld_grpc.pb.go @@ -44,7 +44,7 @@ func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ... type GreeterServer interface { // Sends a greeting SayHello(context.Context, *HelloRequest) (*HelloReply, error) - unimplementedGreeterServer() + mustEmbedUnimplementedGreeterServer() } // UnimplementedGreeterServer must be embedded to have forward compatible implementations. @@ -54,7 +54,7 @@ type UnimplementedGreeterServer struct { func (*UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } -func (*UnimplementedGreeterServer) unimplementedGreeterServer() {} +func (*UnimplementedGreeterServer) mustEmbedUnimplementedGreeterServer() {} func RegisterGreeterServer(s *grpc.Server, srv GreeterServer) { s.RegisterService(&_Greeter_serviceDesc, srv) diff --git a/examples/route_guide/routeguide/route_guide_grpc.pb.go b/examples/route_guide/routeguide/route_guide_grpc.pb.go index 76b43c66b7e1..0254f5dbc6cc 100644 --- a/examples/route_guide/routeguide/route_guide_grpc.pb.go +++ b/examples/route_guide/routeguide/route_guide_grpc.pb.go @@ -185,7 +185,7 @@ type RouteGuideServer interface { // Accepts a stream of RouteNotes sent while a route is being traversed, // while receiving other RouteNotes (e.g. from other users). RouteChat(RouteGuide_RouteChatServer) error - unimplementedRouteGuideServer() + mustEmbedUnimplementedRouteGuideServer() } // UnimplementedRouteGuideServer must be embedded to have forward compatible implementations. @@ -204,7 +204,7 @@ func (*UnimplementedRouteGuideServer) RecordRoute(RouteGuide_RecordRouteServer) func (*UnimplementedRouteGuideServer) RouteChat(RouteGuide_RouteChatServer) error { return status.Errorf(codes.Unimplemented, "method RouteChat not implemented") } -func (*UnimplementedRouteGuideServer) unimplementedRouteGuideServer() {} +func (*UnimplementedRouteGuideServer) mustEmbedUnimplementedRouteGuideServer() {} func RegisterRouteGuideServer(s *grpc.Server, srv RouteGuideServer) { s.RegisterService(&_RouteGuide_serviceDesc, srv) diff --git a/health/grpc_health_v1/health_grpc.pb.go b/health/grpc_health_v1/health_grpc.pb.go index b469f5de965b..6fcab3c9641e 100644 --- a/health/grpc_health_v1/health_grpc.pb.go +++ b/health/grpc_health_v1/health_grpc.pb.go @@ -110,7 +110,7 @@ type HealthServer interface { // call. If the call terminates with any other status (including OK), // clients should retry the call with appropriate exponential backoff. Watch(*HealthCheckRequest, Health_WatchServer) error - unimplementedHealthServer() + mustEmbedUnimplementedHealthServer() } // UnimplementedHealthServer must be embedded to have forward compatible implementations. @@ -123,7 +123,7 @@ func (*UnimplementedHealthServer) Check(context.Context, *HealthCheckRequest) (* func (*UnimplementedHealthServer) Watch(*HealthCheckRequest, Health_WatchServer) error { return status.Errorf(codes.Unimplemented, "method Watch not implemented") } -func (*UnimplementedHealthServer) unimplementedHealthServer() {} +func (*UnimplementedHealthServer) mustEmbedUnimplementedHealthServer() {} func RegisterHealthServer(s *grpc.Server, srv HealthServer) { s.RegisterService(&_Health_serviceDesc, srv) diff --git a/interop/grpc_testing/test_grpc.pb.go b/interop/grpc_testing/test_grpc.pb.go index bfd05d8eb0c9..50f4e9100c15 100644 --- a/interop/grpc_testing/test_grpc.pb.go +++ b/interop/grpc_testing/test_grpc.pb.go @@ -217,7 +217,7 @@ type TestServiceServer interface { // stream of responses are returned to the client when the server starts with // first request. HalfDuplexCall(TestService_HalfDuplexCallServer) error - unimplementedTestServiceServer() + mustEmbedUnimplementedTestServiceServer() } // UnimplementedTestServiceServer must be embedded to have forward compatible implementations. @@ -242,7 +242,7 @@ func (*UnimplementedTestServiceServer) FullDuplexCall(TestService_FullDuplexCall func (*UnimplementedTestServiceServer) HalfDuplexCall(TestService_HalfDuplexCallServer) error { return status.Errorf(codes.Unimplemented, "method HalfDuplexCall not implemented") } -func (*UnimplementedTestServiceServer) unimplementedTestServiceServer() {} +func (*UnimplementedTestServiceServer) mustEmbedUnimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) @@ -454,7 +454,7 @@ func (c *unimplementedServiceClient) UnimplementedCall(ctx context.Context, in * type UnimplementedServiceServer interface { // A call that no server should implement UnimplementedCall(context.Context, *Empty) (*Empty, error) - unimplementedUnimplementedServiceServer() + mustEmbedUnimplementedUnimplementedServiceServer() } // UnimplementedUnimplementedServiceServer must be embedded to have forward compatible implementations. @@ -464,7 +464,7 @@ type UnimplementedUnimplementedServiceServer struct { func (*UnimplementedUnimplementedServiceServer) UnimplementedCall(context.Context, *Empty) (*Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method UnimplementedCall not implemented") } -func (*UnimplementedUnimplementedServiceServer) unimplementedUnimplementedServiceServer() {} +func (*UnimplementedUnimplementedServiceServer) mustEmbedUnimplementedUnimplementedServiceServer() {} func RegisterUnimplementedServiceServer(s *grpc.Server, srv UnimplementedServiceServer) { s.RegisterService(&_UnimplementedService_serviceDesc, srv) @@ -532,7 +532,7 @@ func (c *loadBalancerStatsServiceClient) GetClientStats(ctx context.Context, in type LoadBalancerStatsServiceServer interface { // Gets the backend distribution for RPCs sent by a test client. GetClientStats(context.Context, *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) - unimplementedLoadBalancerStatsServiceServer() + mustEmbedUnimplementedLoadBalancerStatsServiceServer() } // UnimplementedLoadBalancerStatsServiceServer must be embedded to have forward compatible implementations. @@ -542,7 +542,8 @@ type UnimplementedLoadBalancerStatsServiceServer struct { func (*UnimplementedLoadBalancerStatsServiceServer) GetClientStats(context.Context, *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetClientStats not implemented") } -func (*UnimplementedLoadBalancerStatsServiceServer) unimplementedLoadBalancerStatsServiceServer() {} +func (*UnimplementedLoadBalancerStatsServiceServer) mustEmbedUnimplementedLoadBalancerStatsServiceServer() { +} func RegisterLoadBalancerStatsServiceServer(s *grpc.Server, srv LoadBalancerStatsServiceServer) { s.RegisterService(&_LoadBalancerStatsService_serviceDesc, srv) diff --git a/profiling/proto/service_grpc.pb.go b/profiling/proto/service_grpc.pb.go index bcf555305388..3e1cf1f4ca7f 100644 --- a/profiling/proto/service_grpc.pb.go +++ b/profiling/proto/service_grpc.pb.go @@ -59,7 +59,7 @@ type ProfilingServer interface { // GetStreamStats is used to retrieve an array of stream-level stats from a // gRPC client/server. GetStreamStats(context.Context, *GetStreamStatsRequest) (*GetStreamStatsResponse, error) - unimplementedProfilingServer() + mustEmbedUnimplementedProfilingServer() } // UnimplementedProfilingServer must be embedded to have forward compatible implementations. @@ -72,7 +72,7 @@ func (*UnimplementedProfilingServer) Enable(context.Context, *EnableRequest) (*E func (*UnimplementedProfilingServer) GetStreamStats(context.Context, *GetStreamStatsRequest) (*GetStreamStatsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetStreamStats not implemented") } -func (*UnimplementedProfilingServer) unimplementedProfilingServer() {} +func (*UnimplementedProfilingServer) mustEmbedUnimplementedProfilingServer() {} func RegisterProfilingServer(s *grpc.Server, srv ProfilingServer) { s.RegisterService(&_Profiling_serviceDesc, srv) diff --git a/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go b/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go index f868330365af..aa03e10bcd35 100644 --- a/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go +++ b/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go @@ -68,7 +68,7 @@ type ServerReflectionServer interface { // The reflection service is structured as a bidirectional stream, ensuring // all related requests go to a single server. ServerReflectionInfo(ServerReflection_ServerReflectionInfoServer) error - unimplementedServerReflectionServer() + mustEmbedUnimplementedServerReflectionServer() } // UnimplementedServerReflectionServer must be embedded to have forward compatible implementations. @@ -78,7 +78,7 @@ type UnimplementedServerReflectionServer struct { func (*UnimplementedServerReflectionServer) ServerReflectionInfo(ServerReflection_ServerReflectionInfoServer) error { return status.Errorf(codes.Unimplemented, "method ServerReflectionInfo not implemented") } -func (*UnimplementedServerReflectionServer) unimplementedServerReflectionServer() {} +func (*UnimplementedServerReflectionServer) mustEmbedUnimplementedServerReflectionServer() {} func RegisterServerReflectionServer(s *grpc.Server, srv ServerReflectionServer) { s.RegisterService(&_ServerReflection_serviceDesc, srv) diff --git a/reflection/grpc_testing/test_grpc.pb.go b/reflection/grpc_testing/test_grpc.pb.go index 2e4ccd8eca04..acc6f514515c 100644 --- a/reflection/grpc_testing/test_grpc.pb.go +++ b/reflection/grpc_testing/test_grpc.pb.go @@ -75,7 +75,7 @@ func (x *searchServiceStreamingSearchClient) Recv() (*SearchResponse, error) { type SearchServiceServer interface { Search(context.Context, *SearchRequest) (*SearchResponse, error) StreamingSearch(SearchService_StreamingSearchServer) error - unimplementedSearchServiceServer() + mustEmbedUnimplementedSearchServiceServer() } // UnimplementedSearchServiceServer must be embedded to have forward compatible implementations. @@ -88,7 +88,7 @@ func (*UnimplementedSearchServiceServer) Search(context.Context, *SearchRequest) func (*UnimplementedSearchServiceServer) StreamingSearch(SearchService_StreamingSearchServer) error { return status.Errorf(codes.Unimplemented, "method StreamingSearch not implemented") } -func (*UnimplementedSearchServiceServer) unimplementedSearchServiceServer() {} +func (*UnimplementedSearchServiceServer) mustEmbedUnimplementedSearchServiceServer() {} func RegisterSearchServiceServer(s *grpc.Server, srv SearchServiceServer) { s.RegisterService(&_SearchService_serviceDesc, srv) diff --git a/stats/grpc_testing/test_grpc.pb.go b/stats/grpc_testing/test_grpc.pb.go index 3778a3ef33e4..286c82dfa171 100644 --- a/stats/grpc_testing/test_grpc.pb.go +++ b/stats/grpc_testing/test_grpc.pb.go @@ -159,7 +159,7 @@ type TestServiceServer interface { ClientStreamCall(TestService_ClientStreamCallServer) error // Server stream ServerStreamCall(*SimpleRequest, TestService_ServerStreamCallServer) error - unimplementedTestServiceServer() + mustEmbedUnimplementedTestServiceServer() } // UnimplementedTestServiceServer must be embedded to have forward compatible implementations. @@ -178,7 +178,7 @@ func (*UnimplementedTestServiceServer) ClientStreamCall(TestService_ClientStream func (*UnimplementedTestServiceServer) ServerStreamCall(*SimpleRequest, TestService_ServerStreamCallServer) error { return status.Errorf(codes.Unimplemented, "method ServerStreamCall not implemented") } -func (*UnimplementedTestServiceServer) unimplementedTestServiceServer() {} +func (*UnimplementedTestServiceServer) mustEmbedUnimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) diff --git a/stress/grpc_testing/metrics_grpc.pb.go b/stress/grpc_testing/metrics_grpc.pb.go index 8ca55b26bab7..d9cdd80fe0e8 100644 --- a/stress/grpc_testing/metrics_grpc.pb.go +++ b/stress/grpc_testing/metrics_grpc.pb.go @@ -82,7 +82,7 @@ type MetricsServiceServer interface { GetAllGauges(*EmptyMessage, MetricsService_GetAllGaugesServer) error // Returns the value of one gauge GetGauge(context.Context, *GaugeRequest) (*GaugeResponse, error) - unimplementedMetricsServiceServer() + mustEmbedUnimplementedMetricsServiceServer() } // UnimplementedMetricsServiceServer must be embedded to have forward compatible implementations. @@ -95,7 +95,7 @@ func (*UnimplementedMetricsServiceServer) GetAllGauges(*EmptyMessage, MetricsSer func (*UnimplementedMetricsServiceServer) GetGauge(context.Context, *GaugeRequest) (*GaugeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetGauge not implemented") } -func (*UnimplementedMetricsServiceServer) unimplementedMetricsServiceServer() {} +func (*UnimplementedMetricsServiceServer) mustEmbedUnimplementedMetricsServiceServer() {} func RegisterMetricsServiceServer(s *grpc.Server, srv MetricsServiceServer) { s.RegisterService(&_MetricsService_serviceDesc, srv) diff --git a/test/grpc_testing/test_grpc.pb.go b/test/grpc_testing/test_grpc.pb.go index 2b93b84118b8..d5771cd65073 100644 --- a/test/grpc_testing/test_grpc.pb.go +++ b/test/grpc_testing/test_grpc.pb.go @@ -217,7 +217,7 @@ type TestServiceServer interface { // stream of responses are returned to the client when the server starts with // first request. HalfDuplexCall(TestService_HalfDuplexCallServer) error - unimplementedTestServiceServer() + mustEmbedUnimplementedTestServiceServer() } // UnimplementedTestServiceServer must be embedded to have forward compatible implementations. @@ -242,7 +242,7 @@ func (*UnimplementedTestServiceServer) FullDuplexCall(TestService_FullDuplexCall func (*UnimplementedTestServiceServer) HalfDuplexCall(TestService_HalfDuplexCallServer) error { return status.Errorf(codes.Unimplemented, "method HalfDuplexCall not implemented") } -func (*UnimplementedTestServiceServer) unimplementedTestServiceServer() {} +func (*UnimplementedTestServiceServer) mustEmbedUnimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) From 5c8b3cad0f7ed83817d8968bcbadc558b0139e11 Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Tue, 2 Jun 2020 10:53:35 -0700 Subject: [PATCH 5/8] don't require Unimplemented to be embedded in our .pb.gos, since this would be an API change --- balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go | 1 - balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go | 1 - benchmark/grpc_testing/services_grpc.pb.go | 2 -- channelz/grpc_channelz_v1/channelz_grpc.pb.go | 1 - credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go | 1 - examples/features/proto/echo/echo_grpc.pb.go | 1 - examples/helloworld/helloworld/helloworld_grpc.pb.go | 1 - examples/route_guide/routeguide/route_guide_grpc.pb.go | 1 - health/grpc_health_v1/health_grpc.pb.go | 1 - interop/grpc_testing/test_grpc.pb.go | 3 --- profiling/proto/service_grpc.pb.go | 1 - reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go | 1 - reflection/grpc_testing/test_grpc.pb.go | 1 - regenerate.sh | 2 +- stats/grpc_testing/test_grpc.pb.go | 1 - stress/grpc_testing/metrics_grpc.pb.go | 1 - test/grpc_testing/test_grpc.pb.go | 1 - 17 files changed, 1 insertion(+), 20 deletions(-) diff --git a/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go b/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go index 1477b8e9dcdd..aa16a99e192c 100644 --- a/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go +++ b/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go @@ -66,7 +66,6 @@ func (x *loadBalancerBalanceLoadClient) Recv() (*LoadBalanceResponse, error) { type LoadBalancerServer interface { // Bidirectional rpc to get a list of servers. BalanceLoad(LoadBalancer_BalanceLoadServer) error - mustEmbedUnimplementedLoadBalancerServer() } // UnimplementedLoadBalancerServer must be embedded to have forward compatible implementations. diff --git a/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go b/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go index 1a72ddd79825..298eb79f2466 100644 --- a/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go +++ b/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go @@ -44,7 +44,6 @@ func (c *routeLookupServiceClient) RouteLookup(ctx context.Context, in *RouteLoo type RouteLookupServiceServer interface { // Lookup returns a target for a single key. RouteLookup(context.Context, *RouteLookupRequest) (*RouteLookupResponse, error) - mustEmbedUnimplementedRouteLookupServiceServer() } // UnimplementedRouteLookupServiceServer must be embedded to have forward compatible implementations. diff --git a/benchmark/grpc_testing/services_grpc.pb.go b/benchmark/grpc_testing/services_grpc.pb.go index 14b1d796e4be..5b238bcacd65 100644 --- a/benchmark/grpc_testing/services_grpc.pb.go +++ b/benchmark/grpc_testing/services_grpc.pb.go @@ -120,7 +120,6 @@ type BenchmarkServiceServer interface { // Unconstrainted streaming. // Both server and client keep sending & receiving simultaneously. UnconstrainedStreamingCall(BenchmarkService_UnconstrainedStreamingCallServer) error - mustEmbedUnimplementedBenchmarkServiceServer() } // UnimplementedBenchmarkServiceServer must be embedded to have forward compatible implementations. @@ -372,7 +371,6 @@ type WorkerServiceServer interface { CoreCount(context.Context, *CoreRequest) (*CoreResponse, error) // Quit this worker QuitWorker(context.Context, *Void) (*Void, error) - mustEmbedUnimplementedWorkerServiceServer() } // UnimplementedWorkerServiceServer must be embedded to have forward compatible implementations. diff --git a/channelz/grpc_channelz_v1/channelz_grpc.pb.go b/channelz/grpc_channelz_v1/channelz_grpc.pb.go index 6d58844372cb..634e13b227d5 100644 --- a/channelz/grpc_channelz_v1/channelz_grpc.pb.go +++ b/channelz/grpc_channelz_v1/channelz_grpc.pb.go @@ -124,7 +124,6 @@ type ChannelzServer interface { GetSubchannel(context.Context, *GetSubchannelRequest) (*GetSubchannelResponse, error) // Returns a single Socket or else a NOT_FOUND code. GetSocket(context.Context, *GetSocketRequest) (*GetSocketResponse, error) - mustEmbedUnimplementedChannelzServer() } // UnimplementedChannelzServer must be embedded to have forward compatible implementations. diff --git a/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go b/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go index 631f66edf13c..9ef184118d10 100644 --- a/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go +++ b/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go @@ -76,7 +76,6 @@ type HandshakerServiceServer interface { // service expects to respond. Client does not have to wait for service's // response before sending next request. DoHandshake(HandshakerService_DoHandshakeServer) error - mustEmbedUnimplementedHandshakerServiceServer() } // UnimplementedHandshakerServiceServer must be embedded to have forward compatible implementations. diff --git a/examples/features/proto/echo/echo_grpc.pb.go b/examples/features/proto/echo/echo_grpc.pb.go index 6304d09e7576..65cea4adb86f 100644 --- a/examples/features/proto/echo/echo_grpc.pb.go +++ b/examples/features/proto/echo/echo_grpc.pb.go @@ -153,7 +153,6 @@ type EchoServer interface { ClientStreamingEcho(Echo_ClientStreamingEchoServer) error // BidirectionalStreamingEcho is bidi streaming. BidirectionalStreamingEcho(Echo_BidirectionalStreamingEchoServer) error - mustEmbedUnimplementedEchoServer() } // UnimplementedEchoServer must be embedded to have forward compatible implementations. diff --git a/examples/helloworld/helloworld/helloworld_grpc.pb.go b/examples/helloworld/helloworld/helloworld_grpc.pb.go index 3d48dba48def..58d55d53be70 100644 --- a/examples/helloworld/helloworld/helloworld_grpc.pb.go +++ b/examples/helloworld/helloworld/helloworld_grpc.pb.go @@ -44,7 +44,6 @@ func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ... type GreeterServer interface { // Sends a greeting SayHello(context.Context, *HelloRequest) (*HelloReply, error) - mustEmbedUnimplementedGreeterServer() } // UnimplementedGreeterServer must be embedded to have forward compatible implementations. diff --git a/examples/route_guide/routeguide/route_guide_grpc.pb.go b/examples/route_guide/routeguide/route_guide_grpc.pb.go index 0254f5dbc6cc..f7c233b7d909 100644 --- a/examples/route_guide/routeguide/route_guide_grpc.pb.go +++ b/examples/route_guide/routeguide/route_guide_grpc.pb.go @@ -185,7 +185,6 @@ type RouteGuideServer interface { // Accepts a stream of RouteNotes sent while a route is being traversed, // while receiving other RouteNotes (e.g. from other users). RouteChat(RouteGuide_RouteChatServer) error - mustEmbedUnimplementedRouteGuideServer() } // UnimplementedRouteGuideServer must be embedded to have forward compatible implementations. diff --git a/health/grpc_health_v1/health_grpc.pb.go b/health/grpc_health_v1/health_grpc.pb.go index 6fcab3c9641e..d750429b48de 100644 --- a/health/grpc_health_v1/health_grpc.pb.go +++ b/health/grpc_health_v1/health_grpc.pb.go @@ -110,7 +110,6 @@ type HealthServer interface { // call. If the call terminates with any other status (including OK), // clients should retry the call with appropriate exponential backoff. Watch(*HealthCheckRequest, Health_WatchServer) error - mustEmbedUnimplementedHealthServer() } // UnimplementedHealthServer must be embedded to have forward compatible implementations. diff --git a/interop/grpc_testing/test_grpc.pb.go b/interop/grpc_testing/test_grpc.pb.go index 50f4e9100c15..70f3905f2114 100644 --- a/interop/grpc_testing/test_grpc.pb.go +++ b/interop/grpc_testing/test_grpc.pb.go @@ -217,7 +217,6 @@ type TestServiceServer interface { // stream of responses are returned to the client when the server starts with // first request. HalfDuplexCall(TestService_HalfDuplexCallServer) error - mustEmbedUnimplementedTestServiceServer() } // UnimplementedTestServiceServer must be embedded to have forward compatible implementations. @@ -454,7 +453,6 @@ func (c *unimplementedServiceClient) UnimplementedCall(ctx context.Context, in * type UnimplementedServiceServer interface { // A call that no server should implement UnimplementedCall(context.Context, *Empty) (*Empty, error) - mustEmbedUnimplementedUnimplementedServiceServer() } // UnimplementedUnimplementedServiceServer must be embedded to have forward compatible implementations. @@ -532,7 +530,6 @@ func (c *loadBalancerStatsServiceClient) GetClientStats(ctx context.Context, in type LoadBalancerStatsServiceServer interface { // Gets the backend distribution for RPCs sent by a test client. GetClientStats(context.Context, *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) - mustEmbedUnimplementedLoadBalancerStatsServiceServer() } // UnimplementedLoadBalancerStatsServiceServer must be embedded to have forward compatible implementations. diff --git a/profiling/proto/service_grpc.pb.go b/profiling/proto/service_grpc.pb.go index 3e1cf1f4ca7f..27a1bcd865d1 100644 --- a/profiling/proto/service_grpc.pb.go +++ b/profiling/proto/service_grpc.pb.go @@ -59,7 +59,6 @@ type ProfilingServer interface { // GetStreamStats is used to retrieve an array of stream-level stats from a // gRPC client/server. GetStreamStats(context.Context, *GetStreamStatsRequest) (*GetStreamStatsResponse, error) - mustEmbedUnimplementedProfilingServer() } // UnimplementedProfilingServer must be embedded to have forward compatible implementations. diff --git a/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go b/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go index aa03e10bcd35..18c4942dff03 100644 --- a/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go +++ b/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go @@ -68,7 +68,6 @@ type ServerReflectionServer interface { // The reflection service is structured as a bidirectional stream, ensuring // all related requests go to a single server. ServerReflectionInfo(ServerReflection_ServerReflectionInfoServer) error - mustEmbedUnimplementedServerReflectionServer() } // UnimplementedServerReflectionServer must be embedded to have forward compatible implementations. diff --git a/reflection/grpc_testing/test_grpc.pb.go b/reflection/grpc_testing/test_grpc.pb.go index acc6f514515c..b49731159af1 100644 --- a/reflection/grpc_testing/test_grpc.pb.go +++ b/reflection/grpc_testing/test_grpc.pb.go @@ -75,7 +75,6 @@ func (x *searchServiceStreamingSearchClient) Recv() (*SearchResponse, error) { type SearchServiceServer interface { Search(context.Context, *SearchRequest) (*SearchResponse, error) StreamingSearch(SearchService_StreamingSearchServer) error - mustEmbedUnimplementedSearchServiceServer() } // UnimplementedSearchServiceServer must be embedded to have forward compatible implementations. diff --git a/regenerate.sh b/regenerate.sh index 6f47daf94bc3..987bc20251dd 100755 --- a/regenerate.sh +++ b/regenerate.sh @@ -57,7 +57,7 @@ SOURCES=( OPTS=Mgrpc/service_config/service_config.proto=/internal/proto/grpc_service_config for src in ${SOURCES[@]}; do echo "protoc ${src}" - protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS}:${WORKDIR}/out \ + protoc --go_out=${OPTS}:${WORKDIR}/out --go-grpc_out=${OPTS},requireUnimplementedServers=false:${WORKDIR}/out \ -I"." \ -I${WORKDIR}/grpc-proto \ -I${WORKDIR}/googleapis \ diff --git a/stats/grpc_testing/test_grpc.pb.go b/stats/grpc_testing/test_grpc.pb.go index 286c82dfa171..9789737a205f 100644 --- a/stats/grpc_testing/test_grpc.pb.go +++ b/stats/grpc_testing/test_grpc.pb.go @@ -159,7 +159,6 @@ type TestServiceServer interface { ClientStreamCall(TestService_ClientStreamCallServer) error // Server stream ServerStreamCall(*SimpleRequest, TestService_ServerStreamCallServer) error - mustEmbedUnimplementedTestServiceServer() } // UnimplementedTestServiceServer must be embedded to have forward compatible implementations. diff --git a/stress/grpc_testing/metrics_grpc.pb.go b/stress/grpc_testing/metrics_grpc.pb.go index d9cdd80fe0e8..0c10c99c5384 100644 --- a/stress/grpc_testing/metrics_grpc.pb.go +++ b/stress/grpc_testing/metrics_grpc.pb.go @@ -82,7 +82,6 @@ type MetricsServiceServer interface { GetAllGauges(*EmptyMessage, MetricsService_GetAllGaugesServer) error // Returns the value of one gauge GetGauge(context.Context, *GaugeRequest) (*GaugeResponse, error) - mustEmbedUnimplementedMetricsServiceServer() } // UnimplementedMetricsServiceServer must be embedded to have forward compatible implementations. diff --git a/test/grpc_testing/test_grpc.pb.go b/test/grpc_testing/test_grpc.pb.go index d5771cd65073..642c1a077235 100644 --- a/test/grpc_testing/test_grpc.pb.go +++ b/test/grpc_testing/test_grpc.pb.go @@ -217,7 +217,6 @@ type TestServiceServer interface { // stream of responses are returned to the client when the server starts with // first request. HalfDuplexCall(TestService_HalfDuplexCallServer) error - mustEmbedUnimplementedTestServiceServer() } // UnimplementedTestServiceServer must be embedded to have forward compatible implementations. From 3714849b51afea7bc711f8a0facb256994e2e3fc Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Thu, 4 Jun 2020 08:38:57 -0700 Subject: [PATCH 6/8] tweak comments produced in generated code; add README.md --- .../grpclb/grpc_lb_v1/load_balancer_grpc.pb.go | 5 ++--- .../internal/proto/grpc_lookup_v1/rls_grpc.pb.go | 5 ++--- benchmark/grpc_testing/services_grpc.pb.go | 10 ++++------ channelz/grpc_channelz_v1/channelz_grpc.pb.go | 5 ++--- cmd/protoc-gen-go-grpc/README.md | 15 +++++++++++++++ cmd/protoc-gen-go-grpc/grpc.go | 13 ++++++++++--- .../proto/grpc_gcp/handshaker_grpc.pb.go | 5 ++--- examples/features/proto/echo/echo_grpc.pb.go | 5 ++--- .../helloworld/helloworld/helloworld_grpc.pb.go | 5 ++--- .../routeguide/route_guide_grpc.pb.go | 5 ++--- health/grpc_health_v1/health_grpc.pb.go | 5 ++--- interop/grpc_testing/test_grpc.pb.go | 16 ++++++---------- profiling/proto/service_grpc.pb.go | 5 ++--- .../reflection_grpc.pb.go | 5 ++--- reflection/grpc_testing/test_grpc.pb.go | 5 ++--- stats/grpc_testing/test_grpc.pb.go | 5 ++--- stress/grpc_testing/metrics_grpc.pb.go | 5 ++--- test/grpc_testing/test_grpc.pb.go | 5 ++--- 18 files changed, 63 insertions(+), 61 deletions(-) create mode 100644 cmd/protoc-gen-go-grpc/README.md diff --git a/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go b/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go index aa16a99e192c..5a3a2ec57641 100644 --- a/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go +++ b/balancer/grpclb/grpc_lb_v1/load_balancer_grpc.pb.go @@ -61,21 +61,20 @@ func (x *loadBalancerBalanceLoadClient) Recv() (*LoadBalanceResponse, error) { } // LoadBalancerServer is the server API for LoadBalancer service. -// All implementations must embed UnimplementedLoadBalancerServer +// All implementations should embed UnimplementedLoadBalancerServer // for forward compatibility type LoadBalancerServer interface { // Bidirectional rpc to get a list of servers. BalanceLoad(LoadBalancer_BalanceLoadServer) error } -// UnimplementedLoadBalancerServer must be embedded to have forward compatible implementations. +// UnimplementedLoadBalancerServer should be embedded to have forward compatible implementations. type UnimplementedLoadBalancerServer struct { } func (*UnimplementedLoadBalancerServer) BalanceLoad(LoadBalancer_BalanceLoadServer) error { return status.Errorf(codes.Unimplemented, "method BalanceLoad not implemented") } -func (*UnimplementedLoadBalancerServer) mustEmbedUnimplementedLoadBalancerServer() {} func RegisterLoadBalancerServer(s *grpc.Server, srv LoadBalancerServer) { s.RegisterService(&_LoadBalancer_serviceDesc, srv) diff --git a/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go b/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go index 298eb79f2466..79fa758f7e97 100644 --- a/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go +++ b/balancer/rls/internal/proto/grpc_lookup_v1/rls_grpc.pb.go @@ -39,21 +39,20 @@ func (c *routeLookupServiceClient) RouteLookup(ctx context.Context, in *RouteLoo } // RouteLookupServiceServer is the server API for RouteLookupService service. -// All implementations must embed UnimplementedRouteLookupServiceServer +// All implementations should embed UnimplementedRouteLookupServiceServer // for forward compatibility type RouteLookupServiceServer interface { // Lookup returns a target for a single key. RouteLookup(context.Context, *RouteLookupRequest) (*RouteLookupResponse, error) } -// UnimplementedRouteLookupServiceServer must be embedded to have forward compatible implementations. +// UnimplementedRouteLookupServiceServer should be embedded to have forward compatible implementations. type UnimplementedRouteLookupServiceServer struct { } func (*UnimplementedRouteLookupServiceServer) RouteLookup(context.Context, *RouteLookupRequest) (*RouteLookupResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RouteLookup not implemented") } -func (*UnimplementedRouteLookupServiceServer) mustEmbedUnimplementedRouteLookupServiceServer() {} func RegisterRouteLookupServiceServer(s *grpc.Server, srv RouteLookupServiceServer) { s.RegisterService(&_RouteLookupService_serviceDesc, srv) diff --git a/benchmark/grpc_testing/services_grpc.pb.go b/benchmark/grpc_testing/services_grpc.pb.go index 5b238bcacd65..385870ae5959 100644 --- a/benchmark/grpc_testing/services_grpc.pb.go +++ b/benchmark/grpc_testing/services_grpc.pb.go @@ -108,7 +108,7 @@ func (x *benchmarkServiceUnconstrainedStreamingCallClient) Recv() (*SimpleRespon } // BenchmarkServiceServer is the server API for BenchmarkService service. -// All implementations must embed UnimplementedBenchmarkServiceServer +// All implementations should embed UnimplementedBenchmarkServiceServer // for forward compatibility type BenchmarkServiceServer interface { // One request followed by one response. @@ -122,7 +122,7 @@ type BenchmarkServiceServer interface { UnconstrainedStreamingCall(BenchmarkService_UnconstrainedStreamingCallServer) error } -// UnimplementedBenchmarkServiceServer must be embedded to have forward compatible implementations. +// UnimplementedBenchmarkServiceServer should be embedded to have forward compatible implementations. type UnimplementedBenchmarkServiceServer struct { } @@ -135,7 +135,6 @@ func (*UnimplementedBenchmarkServiceServer) StreamingCall(BenchmarkService_Strea func (*UnimplementedBenchmarkServiceServer) UnconstrainedStreamingCall(BenchmarkService_UnconstrainedStreamingCallServer) error { return status.Errorf(codes.Unimplemented, "method UnconstrainedStreamingCall not implemented") } -func (*UnimplementedBenchmarkServiceServer) mustEmbedUnimplementedBenchmarkServiceServer() {} func RegisterBenchmarkServiceServer(s *grpc.Server, srv BenchmarkServiceServer) { s.RegisterService(&_BenchmarkService_serviceDesc, srv) @@ -350,7 +349,7 @@ func (c *workerServiceClient) QuitWorker(ctx context.Context, in *Void, opts ... } // WorkerServiceServer is the server API for WorkerService service. -// All implementations must embed UnimplementedWorkerServiceServer +// All implementations should embed UnimplementedWorkerServiceServer // for forward compatibility type WorkerServiceServer interface { // Start server with specified workload. @@ -373,7 +372,7 @@ type WorkerServiceServer interface { QuitWorker(context.Context, *Void) (*Void, error) } -// UnimplementedWorkerServiceServer must be embedded to have forward compatible implementations. +// UnimplementedWorkerServiceServer should be embedded to have forward compatible implementations. type UnimplementedWorkerServiceServer struct { } @@ -389,7 +388,6 @@ func (*UnimplementedWorkerServiceServer) CoreCount(context.Context, *CoreRequest func (*UnimplementedWorkerServiceServer) QuitWorker(context.Context, *Void) (*Void, error) { return nil, status.Errorf(codes.Unimplemented, "method QuitWorker not implemented") } -func (*UnimplementedWorkerServiceServer) mustEmbedUnimplementedWorkerServiceServer() {} func RegisterWorkerServiceServer(s *grpc.Server, srv WorkerServiceServer) { s.RegisterService(&_WorkerService_serviceDesc, srv) diff --git a/channelz/grpc_channelz_v1/channelz_grpc.pb.go b/channelz/grpc_channelz_v1/channelz_grpc.pb.go index 634e13b227d5..20e1fe709796 100644 --- a/channelz/grpc_channelz_v1/channelz_grpc.pb.go +++ b/channelz/grpc_channelz_v1/channelz_grpc.pb.go @@ -106,7 +106,7 @@ func (c *channelzClient) GetSocket(ctx context.Context, in *GetSocketRequest, op } // ChannelzServer is the server API for Channelz service. -// All implementations must embed UnimplementedChannelzServer +// All implementations should embed UnimplementedChannelzServer // for forward compatibility type ChannelzServer interface { // Gets all root channels (i.e. channels the application has directly @@ -126,7 +126,7 @@ type ChannelzServer interface { GetSocket(context.Context, *GetSocketRequest) (*GetSocketResponse, error) } -// UnimplementedChannelzServer must be embedded to have forward compatible implementations. +// UnimplementedChannelzServer should be embedded to have forward compatible implementations. type UnimplementedChannelzServer struct { } @@ -151,7 +151,6 @@ func (*UnimplementedChannelzServer) GetSubchannel(context.Context, *GetSubchanne func (*UnimplementedChannelzServer) GetSocket(context.Context, *GetSocketRequest) (*GetSocketResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetSocket not implemented") } -func (*UnimplementedChannelzServer) mustEmbedUnimplementedChannelzServer() {} func RegisterChannelzServer(s *grpc.Server, srv ChannelzServer) { s.RegisterService(&_Channelz_serviceDesc, srv) diff --git a/cmd/protoc-gen-go-grpc/README.md b/cmd/protoc-gen-go-grpc/README.md new file mode 100644 index 000000000000..4358ed9bdb53 --- /dev/null +++ b/cmd/protoc-gen-go-grpc/README.md @@ -0,0 +1,15 @@ +# protoc-gen-go-grpc + +This tool generates Go language bindings of `service`s in protobuf definition +files for gRPC. For usage information, please see our [quick start +guide](https://grpc.io/docs/languages/go/quickstart/). + +By default, to register services using the methods generated by this tool, the +services must embed the corresponding `UnimplementedServer`. This +is a behavior change from the grpc code generator previously included with +`protoc-gen-go`. To restore this behavior, set the option +`requireUnimplementedServers=false`. E.g.: + +``` + protoc --go-grpc_out=requireUnimplementedServers=false[,other options...]:. \ +``` diff --git a/cmd/protoc-gen-go-grpc/grpc.go b/cmd/protoc-gen-go-grpc/grpc.go index 008206ff5036..4f78bdd46018 100644 --- a/cmd/protoc-gen-go-grpc/grpc.go +++ b/cmd/protoc-gen-go-grpc/grpc.go @@ -119,10 +119,15 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated } } + mustOrShould := "must" + if !*requireUnimplemented { + mustOrShould = "should" + } + // Server interface. serverType := service.GoName + "Server" g.P("// ", serverType, " is the server API for ", service.GoName, " service.") - g.P("// All implementations must embed Unimplemented", serverType) + g.P("// All implementations ", mustOrShould, " embed Unimplemented", serverType) g.P("// for forward compatibility") if service.Desc.Options().(*descriptorpb.ServiceOptions).GetDeprecated() { g.P("//") @@ -145,7 +150,7 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P() // Server Unimplemented struct for forward compatibility. - g.P("// Unimplemented", serverType, " must be embedded to have forward compatible implementations.") + g.P("// Unimplemented", serverType, " ", mustOrShould, " be embedded to have forward compatible implementations.") g.P("type Unimplemented", serverType, " struct {") g.P("}") g.P() @@ -158,7 +163,9 @@ func genService(gen *protogen.Plugin, file *protogen.File, g *protogen.Generated g.P("return ", nilArg, statusPackage.Ident("Errorf"), "(", codesPackage.Ident("Unimplemented"), `, "method `, method.GoName, ` not implemented")`) g.P("}") } - g.P("func (*Unimplemented", serverType, ") mustEmbedUnimplemented", serverType, "() {}") + if *requireUnimplemented { + g.P("func (*Unimplemented", serverType, ") mustEmbedUnimplemented", serverType, "() {}") + } g.P() // Server registration. diff --git a/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go b/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go index 9ef184118d10..0e973b8250e3 100644 --- a/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go +++ b/credentials/alts/internal/proto/grpc_gcp/handshaker_grpc.pb.go @@ -66,7 +66,7 @@ func (x *handshakerServiceDoHandshakeClient) Recv() (*HandshakerResp, error) { } // HandshakerServiceServer is the server API for HandshakerService service. -// All implementations must embed UnimplementedHandshakerServiceServer +// All implementations should embed UnimplementedHandshakerServiceServer // for forward compatibility type HandshakerServiceServer interface { // Handshaker service accepts a stream of handshaker request, returning a @@ -78,14 +78,13 @@ type HandshakerServiceServer interface { DoHandshake(HandshakerService_DoHandshakeServer) error } -// UnimplementedHandshakerServiceServer must be embedded to have forward compatible implementations. +// UnimplementedHandshakerServiceServer should be embedded to have forward compatible implementations. type UnimplementedHandshakerServiceServer struct { } func (*UnimplementedHandshakerServiceServer) DoHandshake(HandshakerService_DoHandshakeServer) error { return status.Errorf(codes.Unimplemented, "method DoHandshake not implemented") } -func (*UnimplementedHandshakerServiceServer) mustEmbedUnimplementedHandshakerServiceServer() {} func RegisterHandshakerServiceServer(s *grpc.Server, srv HandshakerServiceServer) { s.RegisterService(&_HandshakerService_serviceDesc, srv) diff --git a/examples/features/proto/echo/echo_grpc.pb.go b/examples/features/proto/echo/echo_grpc.pb.go index 65cea4adb86f..ff36643530ef 100644 --- a/examples/features/proto/echo/echo_grpc.pb.go +++ b/examples/features/proto/echo/echo_grpc.pb.go @@ -142,7 +142,7 @@ func (x *echoBidirectionalStreamingEchoClient) Recv() (*EchoResponse, error) { } // EchoServer is the server API for Echo service. -// All implementations must embed UnimplementedEchoServer +// All implementations should embed UnimplementedEchoServer // for forward compatibility type EchoServer interface { // UnaryEcho is unary echo. @@ -155,7 +155,7 @@ type EchoServer interface { BidirectionalStreamingEcho(Echo_BidirectionalStreamingEchoServer) error } -// UnimplementedEchoServer must be embedded to have forward compatible implementations. +// UnimplementedEchoServer should be embedded to have forward compatible implementations. type UnimplementedEchoServer struct { } @@ -171,7 +171,6 @@ func (*UnimplementedEchoServer) ClientStreamingEcho(Echo_ClientStreamingEchoServ func (*UnimplementedEchoServer) BidirectionalStreamingEcho(Echo_BidirectionalStreamingEchoServer) error { return status.Errorf(codes.Unimplemented, "method BidirectionalStreamingEcho not implemented") } -func (*UnimplementedEchoServer) mustEmbedUnimplementedEchoServer() {} func RegisterEchoServer(s *grpc.Server, srv EchoServer) { s.RegisterService(&_Echo_serviceDesc, srv) diff --git a/examples/helloworld/helloworld/helloworld_grpc.pb.go b/examples/helloworld/helloworld/helloworld_grpc.pb.go index 58d55d53be70..435df1a0e5eb 100644 --- a/examples/helloworld/helloworld/helloworld_grpc.pb.go +++ b/examples/helloworld/helloworld/helloworld_grpc.pb.go @@ -39,21 +39,20 @@ func (c *greeterClient) SayHello(ctx context.Context, in *HelloRequest, opts ... } // GreeterServer is the server API for Greeter service. -// All implementations must embed UnimplementedGreeterServer +// All implementations should embed UnimplementedGreeterServer // for forward compatibility type GreeterServer interface { // Sends a greeting SayHello(context.Context, *HelloRequest) (*HelloReply, error) } -// UnimplementedGreeterServer must be embedded to have forward compatible implementations. +// UnimplementedGreeterServer should be embedded to have forward compatible implementations. type UnimplementedGreeterServer struct { } func (*UnimplementedGreeterServer) SayHello(context.Context, *HelloRequest) (*HelloReply, error) { return nil, status.Errorf(codes.Unimplemented, "method SayHello not implemented") } -func (*UnimplementedGreeterServer) mustEmbedUnimplementedGreeterServer() {} func RegisterGreeterServer(s *grpc.Server, srv GreeterServer) { s.RegisterService(&_Greeter_serviceDesc, srv) diff --git a/examples/route_guide/routeguide/route_guide_grpc.pb.go b/examples/route_guide/routeguide/route_guide_grpc.pb.go index f7c233b7d909..9ae8b4483bfb 100644 --- a/examples/route_guide/routeguide/route_guide_grpc.pb.go +++ b/examples/route_guide/routeguide/route_guide_grpc.pb.go @@ -158,7 +158,7 @@ func (x *routeGuideRouteChatClient) Recv() (*RouteNote, error) { } // RouteGuideServer is the server API for RouteGuide service. -// All implementations must embed UnimplementedRouteGuideServer +// All implementations should embed UnimplementedRouteGuideServer // for forward compatibility type RouteGuideServer interface { // A simple RPC. @@ -187,7 +187,7 @@ type RouteGuideServer interface { RouteChat(RouteGuide_RouteChatServer) error } -// UnimplementedRouteGuideServer must be embedded to have forward compatible implementations. +// UnimplementedRouteGuideServer should be embedded to have forward compatible implementations. type UnimplementedRouteGuideServer struct { } @@ -203,7 +203,6 @@ func (*UnimplementedRouteGuideServer) RecordRoute(RouteGuide_RecordRouteServer) func (*UnimplementedRouteGuideServer) RouteChat(RouteGuide_RouteChatServer) error { return status.Errorf(codes.Unimplemented, "method RouteChat not implemented") } -func (*UnimplementedRouteGuideServer) mustEmbedUnimplementedRouteGuideServer() {} func RegisterRouteGuideServer(s *grpc.Server, srv RouteGuideServer) { s.RegisterService(&_RouteGuide_serviceDesc, srv) diff --git a/health/grpc_health_v1/health_grpc.pb.go b/health/grpc_health_v1/health_grpc.pb.go index d750429b48de..f87e3c92adbe 100644 --- a/health/grpc_health_v1/health_grpc.pb.go +++ b/health/grpc_health_v1/health_grpc.pb.go @@ -88,7 +88,7 @@ func (x *healthWatchClient) Recv() (*HealthCheckResponse, error) { } // HealthServer is the server API for Health service. -// All implementations must embed UnimplementedHealthServer +// All implementations should embed UnimplementedHealthServer // for forward compatibility type HealthServer interface { // If the requested service is unknown, the call will fail with status @@ -112,7 +112,7 @@ type HealthServer interface { Watch(*HealthCheckRequest, Health_WatchServer) error } -// UnimplementedHealthServer must be embedded to have forward compatible implementations. +// UnimplementedHealthServer should be embedded to have forward compatible implementations. type UnimplementedHealthServer struct { } @@ -122,7 +122,6 @@ func (*UnimplementedHealthServer) Check(context.Context, *HealthCheckRequest) (* func (*UnimplementedHealthServer) Watch(*HealthCheckRequest, Health_WatchServer) error { return status.Errorf(codes.Unimplemented, "method Watch not implemented") } -func (*UnimplementedHealthServer) mustEmbedUnimplementedHealthServer() {} func RegisterHealthServer(s *grpc.Server, srv HealthServer) { s.RegisterService(&_Health_serviceDesc, srv) diff --git a/interop/grpc_testing/test_grpc.pb.go b/interop/grpc_testing/test_grpc.pb.go index 70f3905f2114..07b555a3f690 100644 --- a/interop/grpc_testing/test_grpc.pb.go +++ b/interop/grpc_testing/test_grpc.pb.go @@ -194,7 +194,7 @@ func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, } // TestServiceServer is the server API for TestService service. -// All implementations must embed UnimplementedTestServiceServer +// All implementations should embed UnimplementedTestServiceServer // for forward compatibility type TestServiceServer interface { // One empty request followed by one empty response. @@ -219,7 +219,7 @@ type TestServiceServer interface { HalfDuplexCall(TestService_HalfDuplexCallServer) error } -// UnimplementedTestServiceServer must be embedded to have forward compatible implementations. +// UnimplementedTestServiceServer should be embedded to have forward compatible implementations. type UnimplementedTestServiceServer struct { } @@ -241,7 +241,6 @@ func (*UnimplementedTestServiceServer) FullDuplexCall(TestService_FullDuplexCall func (*UnimplementedTestServiceServer) HalfDuplexCall(TestService_HalfDuplexCallServer) error { return status.Errorf(codes.Unimplemented, "method HalfDuplexCall not implemented") } -func (*UnimplementedTestServiceServer) mustEmbedUnimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) @@ -448,21 +447,20 @@ func (c *unimplementedServiceClient) UnimplementedCall(ctx context.Context, in * } // UnimplementedServiceServer is the server API for UnimplementedService service. -// All implementations must embed UnimplementedUnimplementedServiceServer +// All implementations should embed UnimplementedUnimplementedServiceServer // for forward compatibility type UnimplementedServiceServer interface { // A call that no server should implement UnimplementedCall(context.Context, *Empty) (*Empty, error) } -// UnimplementedUnimplementedServiceServer must be embedded to have forward compatible implementations. +// UnimplementedUnimplementedServiceServer should be embedded to have forward compatible implementations. type UnimplementedUnimplementedServiceServer struct { } func (*UnimplementedUnimplementedServiceServer) UnimplementedCall(context.Context, *Empty) (*Empty, error) { return nil, status.Errorf(codes.Unimplemented, "method UnimplementedCall not implemented") } -func (*UnimplementedUnimplementedServiceServer) mustEmbedUnimplementedUnimplementedServiceServer() {} func RegisterUnimplementedServiceServer(s *grpc.Server, srv UnimplementedServiceServer) { s.RegisterService(&_UnimplementedService_serviceDesc, srv) @@ -525,22 +523,20 @@ func (c *loadBalancerStatsServiceClient) GetClientStats(ctx context.Context, in } // LoadBalancerStatsServiceServer is the server API for LoadBalancerStatsService service. -// All implementations must embed UnimplementedLoadBalancerStatsServiceServer +// All implementations should embed UnimplementedLoadBalancerStatsServiceServer // for forward compatibility type LoadBalancerStatsServiceServer interface { // Gets the backend distribution for RPCs sent by a test client. GetClientStats(context.Context, *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) } -// UnimplementedLoadBalancerStatsServiceServer must be embedded to have forward compatible implementations. +// UnimplementedLoadBalancerStatsServiceServer should be embedded to have forward compatible implementations. type UnimplementedLoadBalancerStatsServiceServer struct { } func (*UnimplementedLoadBalancerStatsServiceServer) GetClientStats(context.Context, *LoadBalancerStatsRequest) (*LoadBalancerStatsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetClientStats not implemented") } -func (*UnimplementedLoadBalancerStatsServiceServer) mustEmbedUnimplementedLoadBalancerStatsServiceServer() { -} func RegisterLoadBalancerStatsServiceServer(s *grpc.Server, srv LoadBalancerStatsServiceServer) { s.RegisterService(&_LoadBalancerStatsService_serviceDesc, srv) diff --git a/profiling/proto/service_grpc.pb.go b/profiling/proto/service_grpc.pb.go index 27a1bcd865d1..aed8d58762d3 100644 --- a/profiling/proto/service_grpc.pb.go +++ b/profiling/proto/service_grpc.pb.go @@ -51,7 +51,7 @@ func (c *profilingClient) GetStreamStats(ctx context.Context, in *GetStreamStats } // ProfilingServer is the server API for Profiling service. -// All implementations must embed UnimplementedProfilingServer +// All implementations should embed UnimplementedProfilingServer // for forward compatibility type ProfilingServer interface { // Enable allows users to toggle profiling on and off remotely. @@ -61,7 +61,7 @@ type ProfilingServer interface { GetStreamStats(context.Context, *GetStreamStatsRequest) (*GetStreamStatsResponse, error) } -// UnimplementedProfilingServer must be embedded to have forward compatible implementations. +// UnimplementedProfilingServer should be embedded to have forward compatible implementations. type UnimplementedProfilingServer struct { } @@ -71,7 +71,6 @@ func (*UnimplementedProfilingServer) Enable(context.Context, *EnableRequest) (*E func (*UnimplementedProfilingServer) GetStreamStats(context.Context, *GetStreamStatsRequest) (*GetStreamStatsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetStreamStats not implemented") } -func (*UnimplementedProfilingServer) mustEmbedUnimplementedProfilingServer() {} func RegisterProfilingServer(s *grpc.Server, srv ProfilingServer) { s.RegisterService(&_Profiling_serviceDesc, srv) diff --git a/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go b/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go index 18c4942dff03..2294b2c6c9e5 100644 --- a/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go +++ b/reflection/grpc_reflection_v1alpha/reflection_grpc.pb.go @@ -62,7 +62,7 @@ func (x *serverReflectionServerReflectionInfoClient) Recv() (*ServerReflectionRe } // ServerReflectionServer is the server API for ServerReflection service. -// All implementations must embed UnimplementedServerReflectionServer +// All implementations should embed UnimplementedServerReflectionServer // for forward compatibility type ServerReflectionServer interface { // The reflection service is structured as a bidirectional stream, ensuring @@ -70,14 +70,13 @@ type ServerReflectionServer interface { ServerReflectionInfo(ServerReflection_ServerReflectionInfoServer) error } -// UnimplementedServerReflectionServer must be embedded to have forward compatible implementations. +// UnimplementedServerReflectionServer should be embedded to have forward compatible implementations. type UnimplementedServerReflectionServer struct { } func (*UnimplementedServerReflectionServer) ServerReflectionInfo(ServerReflection_ServerReflectionInfoServer) error { return status.Errorf(codes.Unimplemented, "method ServerReflectionInfo not implemented") } -func (*UnimplementedServerReflectionServer) mustEmbedUnimplementedServerReflectionServer() {} func RegisterServerReflectionServer(s *grpc.Server, srv ServerReflectionServer) { s.RegisterService(&_ServerReflection_serviceDesc, srv) diff --git a/reflection/grpc_testing/test_grpc.pb.go b/reflection/grpc_testing/test_grpc.pb.go index b49731159af1..95cd2bab1c22 100644 --- a/reflection/grpc_testing/test_grpc.pb.go +++ b/reflection/grpc_testing/test_grpc.pb.go @@ -70,14 +70,14 @@ func (x *searchServiceStreamingSearchClient) Recv() (*SearchResponse, error) { } // SearchServiceServer is the server API for SearchService service. -// All implementations must embed UnimplementedSearchServiceServer +// All implementations should embed UnimplementedSearchServiceServer // for forward compatibility type SearchServiceServer interface { Search(context.Context, *SearchRequest) (*SearchResponse, error) StreamingSearch(SearchService_StreamingSearchServer) error } -// UnimplementedSearchServiceServer must be embedded to have forward compatible implementations. +// UnimplementedSearchServiceServer should be embedded to have forward compatible implementations. type UnimplementedSearchServiceServer struct { } @@ -87,7 +87,6 @@ func (*UnimplementedSearchServiceServer) Search(context.Context, *SearchRequest) func (*UnimplementedSearchServiceServer) StreamingSearch(SearchService_StreamingSearchServer) error { return status.Errorf(codes.Unimplemented, "method StreamingSearch not implemented") } -func (*UnimplementedSearchServiceServer) mustEmbedUnimplementedSearchServiceServer() {} func RegisterSearchServiceServer(s *grpc.Server, srv SearchServiceServer) { s.RegisterService(&_SearchService_serviceDesc, srv) diff --git a/stats/grpc_testing/test_grpc.pb.go b/stats/grpc_testing/test_grpc.pb.go index 9789737a205f..98da3340b76a 100644 --- a/stats/grpc_testing/test_grpc.pb.go +++ b/stats/grpc_testing/test_grpc.pb.go @@ -145,7 +145,7 @@ func (x *testServiceServerStreamCallClient) Recv() (*SimpleResponse, error) { } // TestServiceServer is the server API for TestService service. -// All implementations must embed UnimplementedTestServiceServer +// All implementations should embed UnimplementedTestServiceServer // for forward compatibility type TestServiceServer interface { // One request followed by one response. @@ -161,7 +161,7 @@ type TestServiceServer interface { ServerStreamCall(*SimpleRequest, TestService_ServerStreamCallServer) error } -// UnimplementedTestServiceServer must be embedded to have forward compatible implementations. +// UnimplementedTestServiceServer should be embedded to have forward compatible implementations. type UnimplementedTestServiceServer struct { } @@ -177,7 +177,6 @@ func (*UnimplementedTestServiceServer) ClientStreamCall(TestService_ClientStream func (*UnimplementedTestServiceServer) ServerStreamCall(*SimpleRequest, TestService_ServerStreamCallServer) error { return status.Errorf(codes.Unimplemented, "method ServerStreamCall not implemented") } -func (*UnimplementedTestServiceServer) mustEmbedUnimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) diff --git a/stress/grpc_testing/metrics_grpc.pb.go b/stress/grpc_testing/metrics_grpc.pb.go index 0c10c99c5384..3a232ff8501b 100644 --- a/stress/grpc_testing/metrics_grpc.pb.go +++ b/stress/grpc_testing/metrics_grpc.pb.go @@ -74,7 +74,7 @@ func (c *metricsServiceClient) GetGauge(ctx context.Context, in *GaugeRequest, o } // MetricsServiceServer is the server API for MetricsService service. -// All implementations must embed UnimplementedMetricsServiceServer +// All implementations should embed UnimplementedMetricsServiceServer // for forward compatibility type MetricsServiceServer interface { // Returns the values of all the gauges that are currently being maintained by @@ -84,7 +84,7 @@ type MetricsServiceServer interface { GetGauge(context.Context, *GaugeRequest) (*GaugeResponse, error) } -// UnimplementedMetricsServiceServer must be embedded to have forward compatible implementations. +// UnimplementedMetricsServiceServer should be embedded to have forward compatible implementations. type UnimplementedMetricsServiceServer struct { } @@ -94,7 +94,6 @@ func (*UnimplementedMetricsServiceServer) GetAllGauges(*EmptyMessage, MetricsSer func (*UnimplementedMetricsServiceServer) GetGauge(context.Context, *GaugeRequest) (*GaugeResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetGauge not implemented") } -func (*UnimplementedMetricsServiceServer) mustEmbedUnimplementedMetricsServiceServer() {} func RegisterMetricsServiceServer(s *grpc.Server, srv MetricsServiceServer) { s.RegisterService(&_MetricsService_serviceDesc, srv) diff --git a/test/grpc_testing/test_grpc.pb.go b/test/grpc_testing/test_grpc.pb.go index 642c1a077235..2340ac05e890 100644 --- a/test/grpc_testing/test_grpc.pb.go +++ b/test/grpc_testing/test_grpc.pb.go @@ -194,7 +194,7 @@ func (x *testServiceHalfDuplexCallClient) Recv() (*StreamingOutputCallResponse, } // TestServiceServer is the server API for TestService service. -// All implementations must embed UnimplementedTestServiceServer +// All implementations should embed UnimplementedTestServiceServer // for forward compatibility type TestServiceServer interface { // One empty request followed by one empty response. @@ -219,7 +219,7 @@ type TestServiceServer interface { HalfDuplexCall(TestService_HalfDuplexCallServer) error } -// UnimplementedTestServiceServer must be embedded to have forward compatible implementations. +// UnimplementedTestServiceServer should be embedded to have forward compatible implementations. type UnimplementedTestServiceServer struct { } @@ -241,7 +241,6 @@ func (*UnimplementedTestServiceServer) FullDuplexCall(TestService_FullDuplexCall func (*UnimplementedTestServiceServer) HalfDuplexCall(TestService_HalfDuplexCallServer) error { return status.Errorf(codes.Unimplemented, "method HalfDuplexCall not implemented") } -func (*UnimplementedTestServiceServer) mustEmbedUnimplementedTestServiceServer() {} func RegisterTestServiceServer(s *grpc.Server, srv TestServiceServer) { s.RegisterService(&_TestService_serviceDesc, srv) From 61f94de3a1cb2a8ab341c2766db7125309ca681e Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Thu, 4 Jun 2020 09:04:39 -0700 Subject: [PATCH 7/8] add 'not recommended' note --- cmd/protoc-gen-go-grpc/README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/protoc-gen-go-grpc/README.md b/cmd/protoc-gen-go-grpc/README.md index 4358ed9bdb53..b26d99ec80bd 100644 --- a/cmd/protoc-gen-go-grpc/README.md +++ b/cmd/protoc-gen-go-grpc/README.md @@ -5,11 +5,15 @@ files for gRPC. For usage information, please see our [quick start guide](https://grpc.io/docs/languages/go/quickstart/). By default, to register services using the methods generated by this tool, the -services must embed the corresponding `UnimplementedServer`. This -is a behavior change from the grpc code generator previously included with -`protoc-gen-go`. To restore this behavior, set the option -`requireUnimplementedServers=false`. E.g.: +service implementations must embed the corresponding +`UnimplementedServer` for future compatibility. This is a behavior +change from the grpc code generator previously included with `protoc-gen-go`. +To restore this behavior, set the option `requireUnimplementedServers=false`. +E.g.: ``` protoc --go-grpc_out=requireUnimplementedServers=false[,other options...]:. \ ``` + +Note that this is not recommended, and the option is only provided to restore +backward compatibility with previously-generated code. From ec61e335a69f68e68ca185478f8b1ab798bbeacc Mon Sep 17 00:00:00 2001 From: Doug Fawley Date: Thu, 4 Jun 2020 10:15:57 -0700 Subject: [PATCH 8/8] future proof --- cmd/protoc-gen-go-grpc/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmd/protoc-gen-go-grpc/README.md b/cmd/protoc-gen-go-grpc/README.md index b26d99ec80bd..f76e419a26c7 100644 --- a/cmd/protoc-gen-go-grpc/README.md +++ b/cmd/protoc-gen-go-grpc/README.md @@ -4,6 +4,8 @@ This tool generates Go language bindings of `service`s in protobuf definition files for gRPC. For usage information, please see our [quick start guide](https://grpc.io/docs/languages/go/quickstart/). +## Future-proofing services + By default, to register services using the methods generated by this tool, the service implementations must embed the corresponding `UnimplementedServer` for future compatibility. This is a behavior