mirror of https://github.com/grpc/grpc-go.git
examples: add Unimplemented___Server to all example servers (#3071)
This commit is contained in:
parent
dcd1c9748d
commit
50c4579fc2
|
|
@ -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{}
|
||||
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) 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: req.Message}, nil
|
||||
}
|
||||
|
||||
// valid validates the authorization.
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
type ecServer struct {
|
||||
pb.UnimplementedEchoServer
|
||||
}
|
||||
|
||||
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: 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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
type ecServer struct {
|
||||
pb.UnimplementedEchoServer
|
||||
}
|
||||
|
||||
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: 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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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{}
|
||||
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 {
|
||||
return status.Error(codes.Unimplemented, "not implemented")
|
||||
}
|
||||
|
||||
func (s *server) ClientStreamingEcho(stream ecpb.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 {
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@ var (
|
|||
)
|
||||
|
||||
type routeGuideServer struct {
|
||||
pb.UnimplementedRouteGuideServer
|
||||
savedFeatures []*pb.Feature // read-only after initialized
|
||||
|
||||
mu sync.Mutex // protects routeNotes
|
||||
|
|
|
|||
Loading…
Reference in New Issue