-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (31 loc) · 907 Bytes
/
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
package main
import (
"html/template"
"github.com/gin-gonic/gin"
"github.com/milosrs/go-hls-server/api"
"github.com/milosrs/go-hls-server/feed/websocket"
"github.com/milosrs/go-hls-server/files"
)
const commonEntry = "frontend/dist"
func main() {
hub := websocket.NewHub()
fileService := files.NewService()
go hub.Start()
go fileService.Start()
router := api.CreateRouter()
router.Static("/frontend/dist", "./frontend/dist")
router.Static("/frontend/src", "./frontend/src")
router.GET("/", func(ctx *gin.Context) {
tmp := template.Must(template.ParseFiles(commonEntry + "/index.html"))
tmp.Execute(ctx.Writer, nil)
})
wsRouter := router.Group("/ws")
wsRouter.GET("/:topic", func(ctx *gin.Context) {
conn := websocket.ServeWS(ctx.Writer, ctx.Request)
files.NewFeed(conn, hub, fileService)
ctx.Status(200)
})
router.Run("localhost:8000")
// Stoping agents
hub.Stop()
}