-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
89 lines (61 loc) · 1.56 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"context"
"errors"
"net/http"
"os"
"os/signal"
"time"
"github.com/shadiestgoat/donations/auth"
"github.com/shadiestgoat/donations/db"
"github.com/shadiestgoat/log"
)
func main() {
InitConfig()
os.Setenv("TZ", "UTC")
cbs := []log.LogCB{
log.NewLoggerPrint(), log.NewLoggerFile("logs/log"),
}
if DEBUG_DISC_WEBHOOK != "" {
mention := DEBUG_DISC_MENTION
if mention != "" {
mention += ", "
}
cbs = append(cbs, log.NewLoggerDiscordWebhook(mention, DEBUG_DISC_WEBHOOK))
}
log.Init(cbs...)
log.Success("Config & Log loaded!")
auth.Load()
log.Success("Snowflake loaded!")
InitFrontend()
log.Success("Frontend loaded!")
db.Init(DB_URI)
log.Success("Database connected!")
defer db.Close()
r := RouterBase()
r.Mount(`/api`, RouterAPI())
log.Success("Server started!")
server := &http.Server{
Addr: ":" + PORT,
Handler: r,
}
go func() {
err := server.ListenAndServe()
if !errors.Is(err, http.ErrServerClosed) {
log.Fatal("HTTP server shut down: %s", err.Error())
}
}()
log.Debug("Running server on *:%v", PORT)
stopper := make(chan os.Signal, 2)
signal.Notify(stopper, os.Interrupt)
log.Success("Everything is ready! You can now press Ctrl+C to shut down <3")
log.PrintSuccess("Also - you can now do 'reload' to reload the 'auths.json' file!")
readLineStopper := make(chan bool)
go processCMD(readLineStopper)
<-stopper
readLineStopper <- true
log.Warn("Shutting down :(")
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
server.Shutdown(ctx)
}