mirror of https://github.com/gin-gonic/gin.git
35 lines
798 B
Go
35 lines
798 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net"
|
|
|
|
pb "github.com/gin-gonic/gin/examples/grpc/pb"
|
|
"golang.org/x/net/context"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/reflection"
|
|
)
|
|
|
|
// server is used to implement helloworld.GreeterServer.
|
|
type server struct{}
|
|
|
|
// SayHello implements helloworld.GreeterServer
|
|
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
|
|
return &pb.HelloReply{Message: "Hello " + in.Name}, nil
|
|
}
|
|
|
|
func main() {
|
|
lis, err := net.Listen("tcp", ":50051")
|
|
if err != nil {
|
|
log.Fatalf("failed to listen: %v", err)
|
|
}
|
|
s := grpc.NewServer()
|
|
pb.RegisterGreeterServer(s, &server{})
|
|
|
|
// Register reflection service on gRPC server.
|
|
reflection.Register(s)
|
|
if err := s.Serve(lis); err != nil {
|
|
log.Fatalf("failed to serve: %v", err)
|
|
}
|
|
}
|