main.go 598 B

123456789101112131415161718192021222324252627
  1. package main
  2. import (
  3. "context"
  4. "log"
  5. "net"
  6. "tutorialserver/qtprotobuf_tutorial"
  7. grpc "google.golang.org/grpc"
  8. )
  9. type echoServer struct{}
  10. func (s *echoServer) Echo(ctx context.Context, req *qtprotobuf_tutorial.EchoRequest) (*qtprotobuf_tutorial.EchoResponse, error) {
  11. return &qtprotobuf_tutorial.EchoResponse{Message: req.Message}, nil
  12. }
  13. func main() {
  14. lis, err := net.Listen("tcp", ":65000")
  15. if err != nil {
  16. log.Fatalf("failed to listen: %v", err)
  17. }
  18. grpcServer := grpc.NewServer()
  19. qtprotobuf_tutorial.RegisterEchoServiceServer(grpcServer, &echoServer{})
  20. grpcServer.Serve(lis)
  21. }