-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
56 lines (49 loc) · 1.51 KB
/
main.go
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
53
54
55
56
package main
import (
"chicko_chat/controllers"
"chicko_chat/database"
"chicko_chat/models"
"chicko_chat/websocket"
"github.com/gin-contrib/cors"
"flag"
"net/http"
"github.com/gin-gonic/gin"
)
func main() {
mongoURI := flag.String("mongoURI", "mongodb://mongo:27017", "Database hostname url")
enableCredentials := flag.Bool("enableCredentials", false, "Enable the use of credentials for mongo connection")
flag.Parse()
db := database.ConnectDatabse(*mongoURI, *enableCredentials)
router := gin.Default()
controller := controllers.Controller{
DB: db,
}
manager := &websocket.BrokerManager{
Brokers: make(map[*data.Broker]bool),
DB: db,
}
websocketServer := &websocket.WsServer{
Manager: manager,
}
router.LoadHTMLGlob("templates/*")
router.GET("/", func(c *gin.Context) {
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Sample Front",
"name": "Moel",
})
})
router.Use(cors.Default())
router.GET("/chat/", controller.JoinRoom)
router.POST("/start/", controller.StartConversationApi)
router.POST("/user-rooms/", controller.GetUserRoomsApi)
router.POST("/create-room/", controller.CreateRoomApi)
router.POST("/room-history/", controller.RoomHistoryApi)
router.POST("/add-user-room/", controller.AddUserToRoomApi)
router.POST("/room-user-details/", controller.GetUserDetailsRoomApi)
router.GET("/ws/:roomId/:userId/", func(c *gin.Context) {
roomId := c.Param("roomId")
userId := c.Param("userId")
websocketServer.ServeWs(c.Writer, c.Request, roomId, userId)
})
router.Run()
}