-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
43 lines (37 loc) · 1004 Bytes
/
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
package main
import (
"flag"
"github.com/rs/zerolog/log"
"os"
"twitch-nightscout/bot"
"twitch-nightscout/config"
"twitch-nightscout/core"
)
func main() {
var configPath string
flag.StringVar(&configPath, "config", "config.yaml", "config file")
data, err := os.ReadFile(configPath)
if os.IsNotExist(err) {
wrote, err := config.WriteExampleConfig(configPath)
switch {
case wrote:
log.Info().Msgf("Wrote example config to '%s'", configPath)
case err != nil:
log.Error().Err(err).Msgf("Could not write example config to '%s' for error", configPath)
case err == nil:
log.Error().Msgf("Could not write example config to '%s' for an unknown reason", configPath)
}
return
}
if err != nil {
log.Err(err).Str("file", configPath).Msg("Reading config file failed")
return
}
cfg, err := config.ReadConfig(data)
if err != nil {
log.Err(err).Str("file", configPath).Msg("Parsing config file failed")
return
}
core.LoggingInitialize(&cfg.Log)
bot.Initialize(cfg)
}