3 * Copyright 2015 gRPC authors.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 //go:generate protoc -I ../helloworld --go_out=plugins=grpc:../helloworld ../helloworld/helloworld.proto
27 "golang.org/x/net/context"
28 "google.golang.org/grpc"
29 pb "google.golang.org/grpc/examples/helloworld/helloworld"
30 "google.golang.org/grpc/reflection"
37 // server is used to implement helloworld.GreeterServer.
40 // SayHello implements helloworld.GreeterServer
41 func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
42 return &pb.HelloReply{Message: "Hello " + in.Name}, nil
46 lis, err := net.Listen("tcp", port)
48 log.Fatalf("failed to listen: %v", err)
51 pb.RegisterGreeterServer(s, &server{})
52 // Register reflection service on gRPC server.
53 reflection.Register(s)
54 if err := s.Serve(lis); err != nil {
55 log.Fatalf("failed to serve: %v", err)