-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (45 loc) · 1.24 KB
/
main.go
File metadata and controls
59 lines (45 loc) · 1.24 KB
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
57
58
59
package main
import (
"networkinator/models"
"log"
"os"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
)
var (
HostCount int
agentClients = make(map[*websocket.Conn]bool)
webClients = make(map[*websocket.Conn]bool)
statusChan = make(chan map[string]interface{})
agentChan = make(chan map[string]interface{})
connChan = make(chan map[string]interface{})
db = ConnectToSQLite()
tomlConf = &models.Config{}
configPath = "config.conf"
)
func main() {
models.ReadConfig(tomlConf, configPath)
f, err := os.OpenFile("server.txt", os.O_RDWR | os.O_CREATE | os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
defer f.Close()
log.SetOutput(f)
gin.SetMode(gin.ReleaseMode)
router := gin.Default()
router.LoadHTMLGlob("templates/**/*")
router.MaxMultipartMemory = 8 << 20 // 8 MiB
router.Static("/assets", "./assets/")
initCookies(router)
public := router.Group("/")
addPublicRoutes(public)
private := router.Group("/")
private.Use(authRequired)
addPrivateRoutes(private)
err = db.AutoMigrate(&models.Connection{}, &models.Agent{})
if err != nil {
log.Fatalln(err)
}
go handleMsg()
log.Fatalln(router.Run(":80"))
}