-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
56 lines (42 loc) · 1.13 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 (
"log"
"os"
"github.com/anothrNick/json-tree-service/database"
"github.com/anothrNick/json-tree-service/web"
"github.com/anothrNick/json-tree-service/websockets"
"github.com/gin-gonic/contrib/static"
"github.com/gin-gonic/gin"
_ "github.com/lib/pq"
)
func main() {
// Making change to test workflows
// and another one
// connect to db
db, err := database.NewPostgres(
os.Getenv("JSONDB_USER"),
os.Getenv("JSONDB_PW"),
os.Getenv("JSONDB_HOST"),
os.Getenv("JSONDB_DB"),
)
if err != nil {
log.Fatal(err)
}
// create a new message dispatcher for websocket connections
dispatcher := websockets.NewDispatcher()
go dispatcher.Run()
// create HTTP handlers
httpHandler := web.NewHandlers(db, dispatcher)
// create websocket handlers
wsHandler := websockets.NewHandlers(dispatcher)
// create router, set routes
router := gin.Default()
// serve frontend static files
router.Use(static.Serve("/", static.LocalFile("./ui/build", true)))
// serve HTTP routes
web.SetRoutes(router, httpHandler)
// serve Websocket routes
websockets.SetRoutes(router, wsHandler)
// run server
router.Run(":5001")
}