Skip to content

Commit 0cd12f8

Browse files
committed
refactor: move to main.go
1 parent 6696635 commit 0cd12f8

File tree

2 files changed

+31
-38
lines changed

2 files changed

+31
-38
lines changed

apps/question-service/grpc.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

apps/question-service/main.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ import (
55
"flag"
66
"fmt"
77
"log"
8+
"net"
89
"net/http"
910
"os"
11+
pb "proto/questionmatching"
1012
"question-service/handlers"
1113
mymiddleware "question-service/middleware"
1214
"question-service/utils"
@@ -19,6 +21,7 @@ import (
1921
"github.com/go-chi/cors"
2022
"github.com/joho/godotenv"
2123
"google.golang.org/api/option"
24+
"google.golang.org/grpc"
2225
)
2326

2427
// initFirestore initializes the Firestore client
@@ -100,9 +103,36 @@ func main() {
100103
}
101104

102105
// Start the server
103-
log.Printf("Starting server on http://localhost:%s", port)
106+
log.Printf("Starting REST server on http://localhost:%s", port)
104107
err = http.ListenAndServe(fmt.Sprintf(":%s", port), r)
105108
if err != nil {
106109
log.Fatalf("Failed to start server: %v", err)
107110
}
108111
}
112+
113+
type server struct {
114+
pb.UnimplementedQuestionMatchingServiceServer // Embed the unimplemented service
115+
}
116+
117+
func initGrpcServer() {
118+
lis, err := net.Listen("tcp", ":50051")
119+
if err != nil {
120+
log.Fatalf("failed to listen: %v", err)
121+
}
122+
s := grpc.NewServer()
123+
pb.RegisterQuestionMatchingServiceServer(s, &server{})
124+
125+
log.Printf("gRPC Server is listening on port 50051...")
126+
if err := s.Serve(lis); err != nil {
127+
log.Fatalf("failed to serve: %v", err)
128+
}
129+
}
130+
131+
func (s *server) FindMatchingQuestion(ctx context.Context, req *pb.MatchQuestionRequest) (*pb.QuestionFound, error) {
132+
return &pb.QuestionFound{
133+
QuestionId: 1,
134+
QuestionName: "abc",
135+
QuestionDifficulty: "Easy",
136+
QuestionTopics: []string{"Algorithms", "Arrays"},
137+
}, nil
138+
}

0 commit comments

Comments
 (0)