diff --git a/examples/features/authentication/server/main.go b/examples/features/authentication/server/main.go index 3ea94cda7e65..63983e1a60d0 100644 --- a/examples/features/authentication/server/main.go +++ b/examples/features/authentication/server/main.go @@ -32,10 +32,11 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" - ecpb "google.golang.org/grpc/examples/features/proto/echo" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" "google.golang.org/grpc/testdata" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) var ( @@ -62,7 +63,7 @@ func main() { grpc.Creds(credentials.NewServerTLSFromCert(&cert)), } s := grpc.NewServer(opts...) - ecpb.RegisterEchoServer(s, &ecServer{}) + pb.RegisterEchoServer(s, &ecServer{}) lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) if err != nil { log.Fatalf("failed to listen: %v", err) @@ -72,19 +73,12 @@ func main() { } } -type ecServer struct{} - -func (s *ecServer) UnaryEcho(ctx context.Context, req *ecpb.EchoRequest) (*ecpb.EchoResponse, error) { - return &ecpb.EchoResponse{Message: req.Message}, nil -} -func (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") +type ecServer struct { + pb.UnimplementedEchoServer } -func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} -func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") + +func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) { + return &pb.EchoResponse{Message: req.Message}, nil } // valid validates the authorization. diff --git a/examples/features/cancellation/server/main.go b/examples/features/cancellation/server/main.go index 2d12bb9028f6..520286bf193e 100644 --- a/examples/features/cancellation/server/main.go +++ b/examples/features/cancellation/server/main.go @@ -20,7 +20,6 @@ package main import ( - "context" "flag" "fmt" "io" @@ -28,25 +27,14 @@ import ( "net" "google.golang.org/grpc" - "google.golang.org/grpc/codes" + pb "google.golang.org/grpc/examples/features/proto/echo" - "google.golang.org/grpc/status" ) var port = flag.Int("port", 50051, "the port to serve on") -type server struct{} - -func (s *server) UnaryEcho(ctx context.Context, in *pb.EchoRequest) (*pb.EchoResponse, error) { - return nil, status.Error(codes.Unimplemented, "not implemented") -} - -func (s *server) ServerStreamingEcho(in *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "not implemented") -} - -func (s *server) ClientStreamingEcho(stream pb.Echo_ClientStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "not implemented") +type server struct { + pb.UnimplementedEchoServer } func (s *server) BidirectionalStreamingEcho(stream pb.Echo_BidirectionalStreamingEchoServer) error { diff --git a/examples/features/compression/server/main.go b/examples/features/compression/server/main.go index f2862c07ad77..e495cc89106b 100644 --- a/examples/features/compression/server/main.go +++ b/examples/features/compression/server/main.go @@ -27,34 +27,22 @@ import ( "net" "google.golang.org/grpc" - "google.golang.org/grpc/codes" - pb "google.golang.org/grpc/examples/features/proto/echo" - "google.golang.org/grpc/status" - _ "google.golang.org/grpc/encoding/gzip" // Install the gzip compressor + + pb "google.golang.org/grpc/examples/features/proto/echo" ) var port = flag.Int("port", 50051, "the port to serve on") -type server struct{} +type server struct { + pb.UnimplementedEchoServer +} func (s *server) UnaryEcho(ctx context.Context, in *pb.EchoRequest) (*pb.EchoResponse, error) { fmt.Printf("UnaryEcho called with message %q\n", in.GetMessage()) return &pb.EchoResponse{Message: in.Message}, nil } -func (s *server) ServerStreamingEcho(in *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "not implemented") -} - -func (s *server) ClientStreamingEcho(stream pb.Echo_ClientStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "not implemented") -} - -func (s *server) BidirectionalStreamingEcho(stream pb.Echo_BidirectionalStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "not implemented") -} - func main() { flag.Parse() diff --git a/examples/features/deadline/server/main.go b/examples/features/deadline/server/main.go index 63044b542b5f..11cd47a6b5b3 100644 --- a/examples/features/deadline/server/main.go +++ b/examples/features/deadline/server/main.go @@ -31,14 +31,16 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" - pb "google.golang.org/grpc/examples/features/proto/echo" "google.golang.org/grpc/status" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) var port = flag.Int("port", 50052, "port number") // server is used to implement EchoServer. type server struct { + pb.UnimplementedEchoServer client pb.EchoClient cc *grpc.ClientConn } @@ -58,14 +60,6 @@ func (s *server) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoRe return &pb.EchoResponse{Message: req.Message}, nil } -func (s *server) ServerStreamingEcho(req *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - -func (s *server) ClientStreamingEcho(stream pb.Echo_ClientStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - func (s *server) BidirectionalStreamingEcho(stream pb.Echo_BidirectionalStreamingEchoServer) error { for { req, err := stream.Recv() diff --git a/examples/features/debugging/server/main.go b/examples/features/debugging/server/main.go index 8dab454d6d68..fcf6714e4fb5 100644 --- a/examples/features/debugging/server/main.go +++ b/examples/features/debugging/server/main.go @@ -27,8 +27,9 @@ import ( "golang.org/x/net/context" "google.golang.org/grpc" "google.golang.org/grpc/channelz/service" - pb "google.golang.org/grpc/examples/helloworld/helloworld" "google.golang.org/grpc/internal/grpcrand" + + pb "google.golang.org/grpc/examples/helloworld/helloworld" ) var ( @@ -36,7 +37,9 @@ var ( ) // server is used to implement helloworld.GreeterServer. -type server struct{} +type server struct { + pb.UnimplementedGreeterServer +} // SayHello implements helloworld.GreeterServer func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { diff --git a/examples/features/encryption/ALTS/server/main.go b/examples/features/encryption/ALTS/server/main.go index f4b84d72f67f..87bedd810f47 100644 --- a/examples/features/encryption/ALTS/server/main.go +++ b/examples/features/encryption/ALTS/server/main.go @@ -27,30 +27,19 @@ import ( "net" "google.golang.org/grpc" - "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials/alts" - ecpb "google.golang.org/grpc/examples/features/proto/echo" - "google.golang.org/grpc/status" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) var port = flag.Int("port", 50051, "the port to serve on") -type ecServer struct{} - -func (s *ecServer) UnaryEcho(ctx context.Context, req *ecpb.EchoRequest) (*ecpb.EchoResponse, error) { - return &ecpb.EchoResponse{Message: req.Message}, nil -} - -func (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} - -func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") +type ecServer struct { + pb.UnimplementedEchoServer } -func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") +func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) { + return &pb.EchoResponse{Message: req.Message}, nil } func main() { @@ -66,7 +55,7 @@ func main() { s := grpc.NewServer(grpc.Creds(altsTC)) // Register EchoServer on the server. - ecpb.RegisterEchoServer(s, &ecServer{}) + pb.RegisterEchoServer(s, &ecServer{}) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) diff --git a/examples/features/encryption/TLS/server/main.go b/examples/features/encryption/TLS/server/main.go index 538a2b87d650..10795178de76 100644 --- a/examples/features/encryption/TLS/server/main.go +++ b/examples/features/encryption/TLS/server/main.go @@ -27,31 +27,20 @@ import ( "net" "google.golang.org/grpc" - "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" - ecpb "google.golang.org/grpc/examples/features/proto/echo" - "google.golang.org/grpc/status" "google.golang.org/grpc/testdata" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) var port = flag.Int("port", 50051, "the port to serve on") -type ecServer struct{} - -func (s *ecServer) UnaryEcho(ctx context.Context, req *ecpb.EchoRequest) (*ecpb.EchoResponse, error) { - return &ecpb.EchoResponse{Message: req.Message}, nil -} - -func (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} - -func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") +type ecServer struct { + pb.UnimplementedEchoServer } -func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") +func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) { + return &pb.EchoResponse{Message: req.Message}, nil } func main() { @@ -71,7 +60,7 @@ func main() { s := grpc.NewServer(grpc.Creds(creds)) // Register EchoServer on the server. - ecpb.RegisterEchoServer(s, &ecServer{}) + pb.RegisterEchoServer(s, &ecServer{}) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) diff --git a/examples/features/errors/server/main.go b/examples/features/errors/server/main.go index d306c4eb0cc3..dc337741ad02 100644 --- a/examples/features/errors/server/main.go +++ b/examples/features/errors/server/main.go @@ -27,17 +27,19 @@ import ( "net" "sync" - epb "google.golang.org/genproto/googleapis/rpc/errdetails" "google.golang.org/grpc" "google.golang.org/grpc/codes" - pb "google.golang.org/grpc/examples/helloworld/helloworld" "google.golang.org/grpc/status" + + epb "google.golang.org/genproto/googleapis/rpc/errdetails" + pb "google.golang.org/grpc/examples/helloworld/helloworld" ) var port = flag.Int("port", 50052, "port number") // server is used to implement helloworld.GreeterServer. type server struct { + pb.UnimplementedGreeterServer mu sync.Mutex count map[string]int } diff --git a/examples/features/interceptor/server/main.go b/examples/features/interceptor/server/main.go index 54ae297c5456..2ad04c1584c5 100644 --- a/examples/features/interceptor/server/main.go +++ b/examples/features/interceptor/server/main.go @@ -32,10 +32,11 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/credentials" - ecpb "google.golang.org/grpc/examples/features/proto/echo" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" "google.golang.org/grpc/testdata" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) var ( @@ -50,22 +51,16 @@ func logger(format string, a ...interface{}) { fmt.Printf("LOG:\t"+format+"\n", a...) } -type server struct{} - -func (s *server) UnaryEcho(ctx context.Context, in *ecpb.EchoRequest) (*ecpb.EchoResponse, error) { - fmt.Printf("unary echoing message %q\n", in.Message) - return &ecpb.EchoResponse{Message: in.Message}, nil -} - -func (s *server) ServerStreamingEcho(in *ecpb.EchoRequest, stream ecpb.Echo_ServerStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "not implemented") +type server struct { + pb.UnimplementedEchoServer } -func (s *server) ClientStreamingEcho(stream ecpb.Echo_ClientStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "not implemented") +func (s *server) UnaryEcho(ctx context.Context, in *pb.EchoRequest) (*pb.EchoResponse, error) { + fmt.Printf("unary echoing message %q\n", in.Message) + return &pb.EchoResponse{Message: in.Message}, nil } -func (s *server) BidirectionalStreamingEcho(stream ecpb.Echo_BidirectionalStreamingEchoServer) error { +func (s *server) BidirectionalStreamingEcho(stream pb.Echo_BidirectionalStreamingEchoServer) error { for { in, err := stream.Recv() if err != nil { @@ -76,7 +71,7 @@ func (s *server) BidirectionalStreamingEcho(stream ecpb.Echo_BidirectionalStream return err } fmt.Printf("bidi echoing message %q\n", in.Message) - stream.Send(&ecpb.EchoResponse{Message: in.Message}) + stream.Send(&pb.EchoResponse{Message: in.Message}) } } @@ -162,7 +157,7 @@ func main() { s := grpc.NewServer(grpc.Creds(creds), grpc.UnaryInterceptor(unaryInterceptor), grpc.StreamInterceptor(streamInterceptor)) // Register EchoServer on the server. - ecpb.RegisterEchoServer(s, &server{}) + pb.RegisterEchoServer(s, &server{}) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) diff --git a/examples/features/keepalive/server/main.go b/examples/features/keepalive/server/main.go index 723a6b906c99..beaa8f710885 100644 --- a/examples/features/keepalive/server/main.go +++ b/examples/features/keepalive/server/main.go @@ -28,10 +28,9 @@ import ( "time" "google.golang.org/grpc" - "google.golang.org/grpc/codes" - pb "google.golang.org/grpc/examples/features/proto/echo" "google.golang.org/grpc/keepalive" - "google.golang.org/grpc/status" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) var port = flag.Int("port", 50052, "port number") @@ -50,24 +49,14 @@ var kasp = keepalive.ServerParameters{ } // server implements EchoServer. -type server struct{} +type server struct { + pb.UnimplementedEchoServer +} func (s *server) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) { return &pb.EchoResponse{Message: req.Message}, nil } -func (s *server) ServerStreamingEcho(req *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - -func (s *server) ClientStreamingEcho(stream pb.Echo_ClientStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - -func (s *server) BidirectionalStreamingEcho(stream pb.Echo_BidirectionalStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - func main() { flag.Parse() diff --git a/examples/features/load_balancing/server/main.go b/examples/features/load_balancing/server/main.go index 8a1dad512897..9d179579ed41 100644 --- a/examples/features/load_balancing/server/main.go +++ b/examples/features/load_balancing/server/main.go @@ -27,9 +27,8 @@ import ( "sync" "google.golang.org/grpc" - "google.golang.org/grpc/codes" - ecpb "google.golang.org/grpc/examples/features/proto/echo" - "google.golang.org/grpc/status" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) var ( @@ -37,20 +36,12 @@ var ( ) type ecServer struct { + pb.UnimplementedEchoServer addr string } -func (s *ecServer) UnaryEcho(ctx context.Context, req *ecpb.EchoRequest) (*ecpb.EchoResponse, error) { - return &ecpb.EchoResponse{Message: fmt.Sprintf("%s (from %s)", req.Message, s.addr)}, nil -} -func (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} -func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} -func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") +func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) { + return &pb.EchoResponse{Message: fmt.Sprintf("%s (from %s)", req.Message, s.addr)}, nil } func startServer(addr string) { @@ -59,7 +50,7 @@ func startServer(addr string) { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() - ecpb.RegisterEchoServer(s, &ecServer{addr: addr}) + pb.RegisterEchoServer(s, &ecServer{addr: addr}) log.Printf("serving on %s\n", addr) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) diff --git a/examples/features/metadata/server/main.go b/examples/features/metadata/server/main.go index a0dd3b86de78..cda3b4978697 100644 --- a/examples/features/metadata/server/main.go +++ b/examples/features/metadata/server/main.go @@ -31,9 +31,10 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" - pb "google.golang.org/grpc/examples/features/proto/echo" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) var port = flag.Int("port", 50051, "the port to serve on") @@ -43,7 +44,9 @@ const ( streamingCount = 10 ) -type server struct{} +type server struct { + pb.UnimplementedEchoServer +} func (s *server) UnaryEcho(ctx context.Context, in *pb.EchoRequest) (*pb.EchoResponse, error) { fmt.Printf("--- UnaryEcho ---\n") diff --git a/examples/features/multiplex/server/main.go b/examples/features/multiplex/server/main.go index 956d36fcfcf8..18da09adda3f 100644 --- a/examples/features/multiplex/server/main.go +++ b/examples/features/multiplex/server/main.go @@ -27,40 +27,31 @@ import ( "net" "google.golang.org/grpc" - "google.golang.org/grpc/codes" + ecpb "google.golang.org/grpc/examples/features/proto/echo" hwpb "google.golang.org/grpc/examples/helloworld/helloworld" - "google.golang.org/grpc/status" ) var port = flag.Int("port", 50051, "the port to serve on") // hwServer is used to implement helloworld.GreeterServer. -type hwServer struct{} +type hwServer struct { + hwpb.UnimplementedGreeterServer +} // SayHello implements helloworld.GreeterServer func (s *hwServer) SayHello(ctx context.Context, in *hwpb.HelloRequest) (*hwpb.HelloReply, error) { return &hwpb.HelloReply{Message: "Hello " + in.Name}, nil } -type ecServer struct{} +type ecServer struct { + ecpb.UnimplementedEchoServer +} func (s *ecServer) UnaryEcho(ctx context.Context, req *ecpb.EchoRequest) (*ecpb.EchoResponse, error) { return &ecpb.EchoResponse{Message: req.Message}, nil } -func (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} - -func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} - -func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} - func main() { flag.Parse() lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) diff --git a/examples/features/name_resolving/server/main.go b/examples/features/name_resolving/server/main.go index d3963a8281b6..1977f44d0c5e 100644 --- a/examples/features/name_resolving/server/main.go +++ b/examples/features/name_resolving/server/main.go @@ -26,28 +26,19 @@ import ( "net" "google.golang.org/grpc" - "google.golang.org/grpc/codes" - ecpb "google.golang.org/grpc/examples/features/proto/echo" - "google.golang.org/grpc/status" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) const addr = "localhost:50051" type ecServer struct { + pb.UnimplementedEchoServer addr string } -func (s *ecServer) UnaryEcho(ctx context.Context, req *ecpb.EchoRequest) (*ecpb.EchoResponse, error) { - return &ecpb.EchoResponse{Message: fmt.Sprintf("%s (from %s)", req.Message, s.addr)}, nil -} -func (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} -func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} -func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") +func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) { + return &pb.EchoResponse{Message: fmt.Sprintf("%s (from %s)", req.Message, s.addr)}, nil } func main() { @@ -56,7 +47,7 @@ func main() { log.Fatalf("failed to listen: %v", err) } s := grpc.NewServer() - ecpb.RegisterEchoServer(s, &ecServer{addr: addr}) + pb.RegisterEchoServer(s, &ecServer{addr: addr}) log.Printf("serving on %s\n", addr) if err := s.Serve(lis); err != nil { log.Fatalf("failed to serve: %v", err) diff --git a/examples/features/reflection/server/main.go b/examples/features/reflection/server/main.go index c5630025d7c0..569273dfdd3e 100644 --- a/examples/features/reflection/server/main.go +++ b/examples/features/reflection/server/main.go @@ -27,41 +27,32 @@ import ( "net" "google.golang.org/grpc" - "google.golang.org/grpc/codes" + "google.golang.org/grpc/reflection" + ecpb "google.golang.org/grpc/examples/features/proto/echo" hwpb "google.golang.org/grpc/examples/helloworld/helloworld" - "google.golang.org/grpc/reflection" - "google.golang.org/grpc/status" ) var port = flag.Int("port", 50051, "the port to serve on") // hwServer is used to implement helloworld.GreeterServer. -type hwServer struct{} +type hwServer struct { + hwpb.UnimplementedGreeterServer +} // SayHello implements helloworld.GreeterServer func (s *hwServer) SayHello(ctx context.Context, in *hwpb.HelloRequest) (*hwpb.HelloReply, error) { return &hwpb.HelloReply{Message: "Hello " + in.Name}, nil } -type ecServer struct{} +type ecServer struct { + ecpb.UnimplementedEchoServer +} func (s *ecServer) UnaryEcho(ctx context.Context, req *ecpb.EchoRequest) (*ecpb.EchoResponse, error) { return &ecpb.EchoResponse{Message: req.Message}, nil } -func (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} - -func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} - -func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error { - return status.Errorf(codes.Unimplemented, "not implemented") -} - func main() { flag.Parse() lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) diff --git a/examples/features/retry/server/main.go b/examples/features/retry/server/main.go index a4450e5b52a6..fdec2f052e27 100644 --- a/examples/features/retry/server/main.go +++ b/examples/features/retry/server/main.go @@ -29,13 +29,15 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" - pb "google.golang.org/grpc/examples/features/proto/echo" "google.golang.org/grpc/status" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) var port = flag.Int("port", 50052, "port number") type failingServer struct { + pb.UnimplementedEchoServer mu sync.Mutex reqCounter uint @@ -65,18 +67,6 @@ func (s *failingServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb return &pb.EchoResponse{Message: req.Message}, nil } -func (s *failingServer) ServerStreamingEcho(req *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - -func (s *failingServer) ClientStreamingEcho(stream pb.Echo_ClientStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - -func (s *failingServer) BidirectionalStreamingEcho(stream pb.Echo_BidirectionalStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - func main() { flag.Parse() diff --git a/examples/features/wait_for_ready/main.go b/examples/features/wait_for_ready/main.go index b7df3bc320f0..f865410f1aa2 100644 --- a/examples/features/wait_for_ready/main.go +++ b/examples/features/wait_for_ready/main.go @@ -29,29 +29,20 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/codes" - pb "google.golang.org/grpc/examples/features/proto/echo" "google.golang.org/grpc/status" + + pb "google.golang.org/grpc/examples/features/proto/echo" ) // server is used to implement EchoServer. -type server struct{} +type server struct { + pb.UnimplementedEchoServer +} func (s *server) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) { return &pb.EchoResponse{Message: req.Message}, nil } -func (s *server) ServerStreamingEcho(req *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - -func (s *server) ClientStreamingEcho(stream pb.Echo_ClientStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - -func (s *server) BidirectionalStreamingEcho(stream pb.Echo_BidirectionalStreamingEchoServer) error { - return status.Error(codes.Unimplemented, "RPC unimplemented") -} - // serve starts listening with a 2 seconds delay. func serve() { lis, err := net.Listen("tcp", ":50053") diff --git a/examples/helloworld/greeter_server/main.go b/examples/helloworld/greeter_server/main.go index eac864548346..eb2fa0ef8e28 100644 --- a/examples/helloworld/greeter_server/main.go +++ b/examples/helloworld/greeter_server/main.go @@ -35,7 +35,9 @@ const ( ) // server is used to implement helloworld.GreeterServer. -type server struct{} +type server struct { + pb.UnimplementedGreeterServer +} // SayHello implements helloworld.GreeterServer func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) { diff --git a/examples/route_guide/server/server.go b/examples/route_guide/server/server.go index b7dc66c81e75..9f523e21f4e6 100644 --- a/examples/route_guide/server/server.go +++ b/examples/route_guide/server/server.go @@ -56,6 +56,7 @@ var ( ) type routeGuideServer struct { + pb.UnimplementedRouteGuideServer savedFeatures []*pb.Feature // read-only after initialized mu sync.Mutex // protects routeNotes