-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (40 loc) · 1.09 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
package main
import (
"github.com/labstack/echo"
"github.com/vpaliy/telex/api"
"github.com/vpaliy/telex/db"
"github.com/vpaliy/telex/di"
"github.com/vpaliy/telex/router"
"github.com/vpaliy/telex/rtm"
"github.com/vpaliy/telex/utils"
)
func registerHTTPHandlers(g *echo.Group, hs ...api.Handler) {
for _, handler := range hs {
handler.Register(g)
}
}
func registerRTM(e *echo.Echo, dispatcher rtm.Dispatcher) {
e.GET("/ws", func(c echo.Context) error {
ws := rtm.NewWebSocket(rtm.DefaultWebSocketConfig)
client := rtm.NewClient(ws, dispatcher, utils.GetToken(c))
return client.ServeHTTP(c.Response(), c.Request())
})
}
func main() {
e := router.New()
api := e.Group("/api")
database, err := db.New(db.CreateTestConfig())
if err != nil {
e.Logger.Fatal(err)
}
defer database.Close()
db.AutoMigrate(database)
registerHTTPHandlers(api,
di.InitializeUserHandler(database),
di.InitializeChannelHandler(database),
di.InitializeMessageHandler(database),
)
dispatcher := di.InitializeDispatcher(database)
registerRTM(e, dispatcher)
e.Logger.Fatal(e.Start("127.0.0.1:8080"))
}