SHARE
TWEET

Untitled

a guest Oct 14th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package server
  2.  
  3. import (
  4.     "context"
  5.     "go.mongodb.org/mongo-driver/mongo"
  6.     "google.golang.org/grpc"
  7.     "log"
  8.     "net"
  9.     "projects/TheFakeBook/pkg/handler"
  10.     proto "projects/TheFakeBook/pkg/service"
  11.     "strconv"
  12. )
  13.  
  14. type server struct {
  15.     mongoClient    *mongo.Client
  16.     serviceHandler *handler.FakeBookHandler
  17. }
  18.  
  19. type StartServiceInput struct {
  20.     MongoClient     *mongo.Client
  21.     GrpcPort        int32
  22.     RestServicePort int32
  23. }
  24.  
  25. func StartService(in StartServiceInput) {
  26.  
  27.     s := grpc.NewServer()
  28.     //Injecting the necessary to DB Layer
  29.     handler := &handler.FakeBookHandler{}
  30.     //TODO: We will inject other attributes later as necessary
  31.  
  32.     proto.RegisterFakeBookServiceServer(s, &server{mongoClient: in.MongoClient, serviceHandler: handler})
  33.     listener, err := net.Listen("tcp", ":"+strconv.Itoa(9981))
  34.     if err != nil {
  35.         log.Fatalf("failed to listen: %v", err)
  36.     }
  37.  
  38.     err = s.Serve(listener)
  39.     if err != nil {
  40.         log.Fatalf("failed to serve: %v", err)
  41.     }
  42. }
  43.  
  44. func (s *server) AddFakeNews(ctx context.Context, input *proto.FakeNewsRequestWrapper) (*proto.FakeNewsResponse, error) {
  45.     panic("implement me")
  46. }
  47. func (s *server) DeleteFakeNews(ctx context.Context, input *proto.FakeNewsRequestWrapper) (*proto.FakeNewsResponse, error) {
  48.     panic("implement me")
  49. }
  50. func (s *server) RateFakeNews(ctx context.Context, input *proto.RatingRequestWrapper) (*proto.FakeNewsResponse, error) {
  51.     panic("implement me")
  52. }
  53. func (s *server) ViewFakeNews(ctx context.Context, input *proto.FakeNewsId) (*proto.FakeNewsResponse, error) {
  54.     panic("implement me")
  55. }
  56. func (s *server) HealthCheck(ctx context.Context, input *proto.HealthRequest) (*proto.HealthReply, error) {
  57.     return &proto.HealthReply{Status: "Up"}, nil
  58. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top