Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: add Unimplemented___Server to all example servers #3071

Merged
merged 2 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions examples/features/authentication/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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)
Expand All @@ -72,18 +73,20 @@ func main() {
}
}

type ecServer struct{}
type ecServer struct {
pb.UnimplementedEchoServer
}

func (s *ecServer) UnaryEcho(ctx context.Context, req *ecpb.EchoRequest) (*ecpb.EchoResponse, error) {
return &ecpb.EchoResponse{Message: req.Message}, nil
func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) {
return &pb.EchoResponse{Message: req.Message}, nil
}
func (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error {
func (s *ecServer) ServerStreamingEcho(*pb.EchoRequest, pb.Echo_ServerStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}
func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error {
func (s *ecServer) ClientStreamingEcho(pb.Echo_ClientStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}
func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error {
func (s *ecServer) BidirectionalStreamingEcho(pb.Echo_BidirectionalStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}
dfawley marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
7 changes: 5 additions & 2 deletions examples/features/cancellation/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,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", 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) {
return nil, status.Error(codes.Unimplemented, "not implemented")
Expand Down
8 changes: 5 additions & 3 deletions examples/features/compression/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
pb "google.golang.org/grpc/examples/features/proto/echo"
_ "google.golang.org/grpc/encoding/gzip" // Install the gzip compressor
"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())
Expand Down
4 changes: 3 additions & 1 deletion examples/features/deadline/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 5 additions & 2 deletions examples/features/debugging/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,19 @@ 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 (
ports = []string{":10001", ":10002", ":10003"}
)

// 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) {
Expand Down
19 changes: 11 additions & 8 deletions examples/features/encryption/ALTS/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,30 @@ import (
"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{}
type ecServer struct {
pb.UnimplementedEchoServer
}

func (s *ecServer) UnaryEcho(ctx context.Context, req *ecpb.EchoRequest) (*ecpb.EchoResponse, error) {
return &ecpb.EchoResponse{Message: req.Message}, nil
func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) {
return &pb.EchoResponse{Message: req.Message}, nil
}

func (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error {
func (s *ecServer) ServerStreamingEcho(*pb.EchoRequest, pb.Echo_ServerStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}

func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error {
func (s *ecServer) ClientStreamingEcho(pb.Echo_ClientStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}

func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error {
func (s *ecServer) BidirectionalStreamingEcho(pb.Echo_BidirectionalStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}

Expand All @@ -66,7 +69,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)
Expand Down
19 changes: 11 additions & 8 deletions examples/features/encryption/TLS/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,31 @@ 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/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{}
type ecServer struct {
pb.UnimplementedEchoServer
}

func (s *ecServer) UnaryEcho(ctx context.Context, req *ecpb.EchoRequest) (*ecpb.EchoResponse, error) {
return &ecpb.EchoResponse{Message: req.Message}, nil
func (s *ecServer) UnaryEcho(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) {
return &pb.EchoResponse{Message: req.Message}, nil
}

func (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error {
func (s *ecServer) ServerStreamingEcho(*pb.EchoRequest, pb.Echo_ServerStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}

func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error {
func (s *ecServer) ClientStreamingEcho(pb.Echo_ClientStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}

func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error {
func (s *ecServer) BidirectionalStreamingEcho(pb.Echo_BidirectionalStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}

Expand All @@ -71,7 +74,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)
Expand Down
6 changes: 4 additions & 2 deletions examples/features/errors/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
21 changes: 12 additions & 9 deletions examples/features/interceptor/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -50,22 +51,24 @@ func logger(format string, a ...interface{}) {
fmt.Printf("LOG:\t"+format+"\n", a...)
}

type server struct{}
type server struct {
pb.UnimplementedEchoServer
}

func (s *server) UnaryEcho(ctx context.Context, in *ecpb.EchoRequest) (*ecpb.EchoResponse, error) {
func (s *server) UnaryEcho(ctx context.Context, in *pb.EchoRequest) (*pb.EchoResponse, error) {
fmt.Printf("unary echoing message %q\n", in.Message)
return &ecpb.EchoResponse{Message: in.Message}, nil
return &pb.EchoResponse{Message: in.Message}, nil
}

func (s *server) ServerStreamingEcho(in *ecpb.EchoRequest, stream ecpb.Echo_ServerStreamingEchoServer) error {
func (s *server) ServerStreamingEcho(in *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer) error {
return status.Error(codes.Unimplemented, "not implemented")
}

func (s *server) ClientStreamingEcho(stream ecpb.Echo_ClientStreamingEchoServer) error {
func (s *server) ClientStreamingEcho(stream pb.Echo_ClientStreamingEchoServer) error {
return status.Error(codes.Unimplemented, "not implemented")
}

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 {
Expand All @@ -76,7 +79,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})
}
}

Expand Down Expand Up @@ -162,7 +165,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)
Expand Down
7 changes: 5 additions & 2 deletions examples/features/keepalive/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import (

"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")
Expand All @@ -50,7 +51,9 @@ 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
Expand Down
16 changes: 9 additions & 7 deletions examples/features/load_balancing/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,30 @@ import (

"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 (
addrs = []string{":50051", ":50052"}
)

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) 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 (s *ecServer) ServerStreamingEcho(*ecpb.EchoRequest, ecpb.Echo_ServerStreamingEchoServer) error {
func (s *ecServer) ServerStreamingEcho(*pb.EchoRequest, pb.Echo_ServerStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}
func (s *ecServer) ClientStreamingEcho(ecpb.Echo_ClientStreamingEchoServer) error {
func (s *ecServer) ClientStreamingEcho(pb.Echo_ClientStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}
func (s *ecServer) BidirectionalStreamingEcho(ecpb.Echo_BidirectionalStreamingEchoServer) error {
func (s *ecServer) BidirectionalStreamingEcho(pb.Echo_BidirectionalStreamingEchoServer) error {
return status.Errorf(codes.Unimplemented, "not implemented")
}

Expand All @@ -59,7 +61,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)
Expand Down
7 changes: 5 additions & 2 deletions examples/features/metadata/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
Loading