1/*
2 *
3 * Copyright 2018 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19// Binary server is an example server.
20package main
21
22import (
23	"context"
24	"flag"
25	"fmt"
26	"log"
27	"net"
28
29	"google.golang.org/grpc"
30	"google.golang.org/grpc/codes"
31	pb "google.golang.org/grpc/examples/features/proto/echo"
32	"google.golang.org/grpc/status"
33
34	_ "google.golang.org/grpc/encoding/gzip" // Install the gzip compressor
35)
36
37var port = flag.Int("port", 50051, "the port to serve on")
38
39type server struct{}
40
41func (s *server) UnaryEcho(ctx context.Context, in *pb.EchoRequest) (*pb.EchoResponse, error) {
42	fmt.Printf("UnaryEcho called with message %q\n", in.GetMessage())
43	return &pb.EchoResponse{Message: in.Message}, nil
44}
45
46func (s *server) ServerStreamingEcho(in *pb.EchoRequest, stream pb.Echo_ServerStreamingEchoServer) error {
47	return status.Error(codes.Unimplemented, "not implemented")
48}
49
50func (s *server) ClientStreamingEcho(stream pb.Echo_ClientStreamingEchoServer) error {
51	return status.Error(codes.Unimplemented, "not implemented")
52}
53
54func (s *server) BidirectionalStreamingEcho(stream pb.Echo_BidirectionalStreamingEchoServer) error {
55	return status.Error(codes.Unimplemented, "not implemented")
56}
57
58func main() {
59	flag.Parse()
60
61	lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
62	if err != nil {
63		log.Fatalf("failed to listen: %v", err)
64	}
65	fmt.Printf("server listening at %v\n", lis.Addr())
66
67	s := grpc.NewServer()
68	pb.RegisterEchoServer(s, &server{})
69	s.Serve(lis)
70}
71