forked from karlkfi/pagerbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
66 lines (53 loc) · 1.59 KB
/
main.go
File metadata and controls
66 lines (53 loc) · 1.59 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
60
61
62
63
64
65
66
package main
import (
"os"
"github.com/karlkfi/pagerbot/internal/config"
"github.com/karlkfi/pagerbot/internal/updater"
log "github.com/sirupsen/logrus"
"github.com/voxelbrain/goptions"
)
type options struct {
Verbose bool `goptions:"-v, --verbose, description='Log verbosely'"`
Pretty bool `goptions:"-p, --pretty, description='Log multi-line pretty-print json'"`
Help goptions.Help `goptions:"-h, --help, description='Show help'"`
Config string `goptions:"-c, --config, description='Path to yaml config file'"`
EnvFile string `goptions:"-e, --env-file, description='Path to environment variable file'"`
}
func main() {
parsedOptions := options{}
parsedOptions.Config = "./config.yml"
goptions.ParseAndFail(&parsedOptions)
if parsedOptions.Verbose {
log.SetLevel(log.DebugLevel)
} else {
log.SetLevel(log.InfoLevel)
}
log.SetFormatter(&log.JSONFormatter{
PrettyPrint: parsedOptions.Pretty,
FieldMap: log.FieldMap{
log.FieldKeyLevel: "severity", // required for StackDriver GKE parsing
},
TimestampFormat: "2006-01-02T15:04:05.000000000Z", // nanoseconds
})
log.Debug("Logging verbosely!")
err := config.Load(parsedOptions.Config, parsedOptions.EnvFile)
if err == nil {
err = config.Config.Validate()
}
if err != nil {
log.WithFields(log.Fields{
"configFile": parsedOptions.Config,
"error": err,
}).Error("Could not load config file")
os.Exit(1)
}
u, err := updater.New()
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Error("Could not start updater")
os.Exit(1)
}
u.Start()
u.Wg.Wait()
}