Skip to content

Commit

Permalink
fix: grpc server
Browse files Browse the repository at this point in the history
  • Loading branch information
tituschewxj committed Oct 24, 2024
1 parent c1f98ee commit 6696635
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
26 changes: 13 additions & 13 deletions apps/question-service/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@ import (
)

type server struct {
pb.UnimplementedQuestionServiceServer // Embed the unimplemented service
pb.UnimplementedQuestionMatchingServiceServer // Embed the unimplemented service
}

func (s *server) FindMatchingQuestion(ctx context.Context, req *pb.MatchQuestionRequest) (*pb.QuestionFound, error) {
return &pb.QuestionFound{
QuestionId: 1,
QuestionName: "abc",
QuestionDifficulty: "Easy",
QuestionTopics: []string{"Algorithms", "Arrays"},
}, nil
}

func initgRPCServer() {
func initGrpcServer() {
lis, err := net.Listen("tcp", ":50051")
if err != nil {
log.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
grpc.NewServer(s, &server{})
pb.RegisterQuestionMatchingServiceServer(s, &server{})

log.Printf("Server is listening on port 50051...")
log.Printf("gRPC Server is listening on port 50051...")
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
}
}

func (s *server) FindMatchingQuestion(ctx context.Context, req *pb.MatchQuestionRequest) (*pb.QuestionFound, error) {
return &pb.QuestionFound{
QuestionId: 1,
QuestionName: "abc",
QuestionDifficulty: "Easy",
QuestionTopics: []string{"Algorithms", "Arrays"},
}, nil
}
2 changes: 2 additions & 0 deletions apps/question-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func main() {
return
}

go initGrpcServer()

// Set up chi router
r := chi.NewRouter()
r.Use(middleware.Logger)
Expand Down

0 comments on commit 6696635

Please sign in to comment.