Skip to content

Commit

Permalink
refactor: move to main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
tituschewxj committed Oct 24, 2024
1 parent 6696635 commit 0cd12f8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 38 deletions.
37 changes: 0 additions & 37 deletions apps/question-service/grpc.go

This file was deleted.

32 changes: 31 additions & 1 deletion apps/question-service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"flag"
"fmt"
"log"
"net"
"net/http"
"os"
pb "proto/questionmatching"
"question-service/handlers"
mymiddleware "question-service/middleware"
"question-service/utils"
Expand All @@ -19,6 +21,7 @@ import (
"github.com/go-chi/cors"
"github.com/joho/godotenv"
"google.golang.org/api/option"
"google.golang.org/grpc"
)

// initFirestore initializes the Firestore client
Expand Down Expand Up @@ -100,9 +103,36 @@ func main() {
}

// Start the server
log.Printf("Starting server on http://localhost:%s", port)
log.Printf("Starting REST server on http://localhost:%s", port)
err = http.ListenAndServe(fmt.Sprintf(":%s", port), r)
if err != nil {
log.Fatalf("Failed to start server: %v", err)
}
}

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

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

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
}

0 comments on commit 0cd12f8

Please sign in to comment.