-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (38 loc) · 1.05 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
package main
import (
api_controllers "github.com/aurora-pool/apollo/api_controllers_v1"
"github.com/aurora-pool/apollo/helpers"
"github.com/aurora-pool/apollo/hub"
"github.com/aurora-pool/apollo/stats"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
)
func main() {
stats.InitRedis()
router := gin.New()
router.Use(gin.Logger())
router.Use(gin.Recovery())
db, err := gorm.Open("mysql", helpers.GetDBurl())
defer db.Close()
hub := hub.NewHub()
go hub.Run()
statsUpdater := stats.NewStats()
go statsUpdater.Run(hub)
if err != nil {
panic(err)
}
router.GET("/", func(c *gin.Context) {
c.JSON(200, map[string]string{"message": "API: welcome to the jungle!"})
})
api := router.Group("/api/v1")
channelCtrl := api_controllers.ChannelCtrl{}
usersCtrl := api_controllers.UsersCtrl{}
channelCtrl.SetDB(db)
channelCtrl.SetHub(hub)
usersCtrl.SetDB(db)
api.GET("/channels", channelCtrl.ChannelIndex)
api.GET("/ws", channelCtrl.WebSocket)
api.GET("/users/:id", usersCtrl.Show)
router.Run(":8442")
}