SHARE
TWEET

Untitled

a guest Oct 14th, 2019 89 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package main
  2.  
  3. import (
  4.     "context"
  5.     "go.mongodb.org/mongo-driver/mongo"
  6.     "go.mongodb.org/mongo-driver/mongo/options"
  7.     "log"
  8.     grpcserver "projects/TheFakeBook/internal/server"
  9. )
  10.  
  11. const (
  12.     grpcPort           = 9981
  13.     gatewayServicePort = 8083
  14.     host               = "localhost"
  15. )
  16.  
  17. func main() {
  18.  
  19.     ctx, cancel := context.WithCancel(context.Background())
  20.     defer cancel()
  21.  
  22.     // setup mongo connection
  23.     mongoConnectionString := "mongodb://127.0.0.1:27017"
  24.     client, err := mongo.Connect(ctx, options.Client().ApplyURI(mongoConnectionString))
  25.     defer client.Disconnect(ctx)
  26.  
  27.     if err != nil {
  28.         log.Fatalf("Failed to connect to MongoDB %v, error: %v", mongoConnectionString, err)
  29.     }
  30.  
  31.     // start grpc server
  32.     log.Printf("GRPC Server listenning on port %v", grpcPort)
  33.     go grpcserver.StartService(grpcserver.StartServiceInput{
  34.         GrpcPort:        grpcPort,
  35.         RestServicePort: gatewayServicePort,
  36.         MongoClient:     client,
  37.     })
  38.  
  39.     //start REST Gateway server
  40.     log.Printf("REST API server listenning on port %v", gatewayServicePort)
  41.     grpcserver.StartGatewayProxy(grpcserver.GrpcGatewayParams{
  42.         ServicePort: gatewayServicePort,
  43.         GrpcPort:    grpcPort,
  44.         Host:        host})
  45.  
  46. }
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
 
Top