Serve starts the gRPC server on the specified address.
(address string, opts ...grpc.ServerOption)
| 127 | |
| 128 | // Serve starts the gRPC server on the specified address. |
| 129 | func (s *Server) Serve(address string, opts ...grpc.ServerOption) error { |
| 130 | lis, err := net.Listen("tcp", address) |
| 131 | if err != nil { |
| 132 | return fmt.Errorf("failed to listen: %w", err) |
| 133 | } |
| 134 | |
| 135 | s.grpcServer = grpc.NewServer(opts...) |
| 136 | proto.RegisterControllerServiceServer(s.grpcServer, s) |
| 137 | proto.RegisterConversationServiceServer(s.grpcServer, s) |
| 138 | |
| 139 | // Register standard gRPC Health Check server |
| 140 | hs := health.NewServer() |
| 141 | hs.SetServingStatus("AX", grpc_health_v1.HealthCheckResponse_SERVING) |
| 142 | grpc_health_v1.RegisterHealthServer(s.grpcServer, hs) |
| 143 | |
| 144 | if err := s.grpcServer.Serve(lis); err != nil { |
| 145 | return fmt.Errorf("failed to serve: %w", err) |
| 146 | } |
| 147 | return nil |
| 148 | } |
| 149 | |
| 150 | // GracefulStop stops the gRPC server gracefully. |
| 151 | func (s *Server) GracefulStop() { |