-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
74 lines (61 loc) · 1.44 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"flag"
"log"
"log/slog"
"os"
"quotient/engine"
"quotient/engine/config"
"quotient/engine/db"
"quotient/www"
)
var logLvels = map[string]slog.Level{
"debug": slog.LevelDebug,
"info": slog.LevelInfo,
"warn": slog.LevelWarn,
"error": slog.LevelError,
}
var opts struct {
logger struct {
level string
}
}
func main() {
// parse command line options
flag.StringVar(&opts.logger.level, "log-level", "debug", "Set the log level")
flag.Parse()
logLevel, ok := logLvels[opts.logger.level]
if !ok {
log.Fatalf("Invalid log level: %s", opts.logger.level)
}
// use config to setup engine
var handler slog.Handler
handler = slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: logLevel})
logger := slog.New(handler)
slog.SetDefault(logger)
// read config file
conf := config.ConfigSettings{}
if err := conf.SetConfig("./config/event.conf"); err != nil {
log.Fatalf("Error reading config file: %v", err)
return
}
// create engine and connect to db
se := engine.NewEngine(&conf)
db.Connect(conf.RequiredSettings.DBConnectURL)
if err := db.AddTeams(&conf); err != nil {
log.Fatalln("Failed to add teams to DB:", err)
}
// load boxes
if err := db.LoadBoxes(&conf); err != nil {
log.Fatalln("Failed to load boxes to DB:", err)
}
// start engine, restart if it stops
go func() {
for {
se.Start()
}
}()
// start web server
router := www.Router{Config: &conf, Engine: se}
router.Start()
}