-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (45 loc) · 1.09 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
package main
import (
"context"
"fmt"
logger "log"
"os"
"os/signal"
"quiz_backend/config"
"quiz_backend/database"
"quiz_backend/quiz"
"quiz_backend/webserver"
"syscall"
"github.com/kesuaheli/twitchgo"
"github.com/spf13/viper"
)
var log = logger.New(logger.Writer(), "[MAIN] ", logger.LstdFlags|logger.Lmsgprefix)
func init() {
config.Load()
}
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGHUP, syscall.SIGINT)
defer cancel()
database.Connect()
err := quiz.FetchQuestions()
if err != nil {
log.Printf("Error getting quiz: %v", err)
os.Exit(-1)
}
webserver.Start(nil, func(err error) {
log.Printf("Error %v", err)
cancel()
})
quiz.TwitchIRC = twitchgo.NewIRCOnly(viper.GetString("twitch.irc_token"))
quiz.TwitchIRC.OnChannelMessage(quiz.OnTwitchChannelMessage)
if err := quiz.TwitchIRC.Connect(); err != nil {
log.Printf("Error connecting to Twitch IRC server: %v", err)
os.Exit(-1)
}
fmt.Println()
fmt.Println("Press Ctrl+C to exit")
fmt.Println()
<-ctx.Done()
fmt.Println()
fmt.Println("Shutting down")
}