-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
52 lines (39 loc) · 1.02 KB
/
main.go
File metadata and controls
52 lines (39 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"log"
"net"
"github.com/ayush00git/goth/db"
grpcserver "github.com/ayush00git/goth/grpc"
"github.com/ayush00git/goth/handlers"
pb "github.com/ayush00git/goth/proto"
"github.com/ayush00git/goth/routes"
"google.golang.org/grpc/reflection"
"google.golang.org/grpc"
"github.com/gin-gonic/gin"
)
func main() {
AuthCollection := db.ConnectMongoDB("users")
// Defining the handlers and routes
db.CreateIndex(AuthCollection)
authHandler := &handlers.AuthHandler{
Collection: AuthCollection,
}
r := gin.Default()
routes.AuthRoute(r, authHandler)
go func() {
log.Println("Server running on port 8080")
log.Fatal(r.Run(":8080"))
} ()
// grpc server
lis, err := net.Listen("tcp", ":50051")
if err != nil {
log.Fatal("failed to listed, err: %v", err)
}
grpcSrv := grpc.NewServer()
pb.RegisterAuthServiceServer(grpcSrv, &grpcserver.AuthGRPCServer{
Collection: AuthCollection,
})
reflection.Register(grpcSrv)
log.Println("gRPC server running on :50051")
log.Fatal(grpcSrv.Serve(lis))
}