-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
56 lines (51 loc) · 1.63 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/gin-contrib/cors"
"github.com/gin-gonic/gin"
)
type SessionToken struct {
Token string `json:"token"`
}
func main() {
homeFolder := GetHomeFolder()
InitHomeFolder(homeFolder)
DB := DbInitialize(homeFolder)
defer DB.CloseDb()
streamController := StreamController{DB}
confController := ConfigController{}
authController := AuthInitialize(DB)
errInit := authController.AuthMiddleware.MiddlewareInit()
if errInit != nil {
log.Fatalf("Failed to initialize auth controller! %s", errInit)
}
app := gin.Default()
app.Use(cors.Default())
app.POST("/login", authController.AuthMiddleware.LoginHandler)
app.POST("/logout", authController.AuthMiddleware.LogoutHandler)
app.POST("/verify-stream", streamController.VerifyStream)
app.POST("/stream-over", streamController.EndStream)
authGroup := app.Group("auth")
authGroup.Use(authController.AuthMiddleware.MiddlewareFunc())
{
authGroup.GET("/verify-token", authController.VerifyToken)
}
streamGroup := app.Group("streams")
streamGroup.Use(authController.AuthMiddleware.MiddlewareFunc())
{
streamGroup.GET("/", streamController.GetStreams)
streamGroup.POST("/create-key", streamController.CreateKey)
streamGroup.DELETE("/:id", streamController.DeleteStream)
}
nginxGroup := app.Group("/nginx")
nginxGroup.Use(authController.AuthMiddleware.MiddlewareFunc())
{
nginxGroup.GET("/config", confController.GetConfiguration)
nginxGroup.POST("/config", confController.UpdateConfiguration)
}
app.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}
func InitHomeFolder(homeFolder string) {
os.MkdirAll(homeFolder, 0644)
}