-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
56 lines (44 loc) · 1.03 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
package main
import (
"github.com/go-logr/logr"
"github.com/go-logr/zerologr"
"github.com/kjbreil/goscript"
"github.com/kjbreil/goscript-example/lights"
"github.com/rs/zerolog"
"os"
"os/signal"
"syscall"
)
func main() {
var modules map[string]interface{}
modules = map[string]interface{}{
"lights": &lights.Lights{},
}
config, err := goscript.ParseConfig("config.yml", modules)
if err != nil {
panic(err)
}
gs, err := goscript.New(config, setupLogging())
if err != nil {
panic(err)
}
gs.AddTriggers(lights.Triggers(gs)...)
err = gs.Connect()
if err != nil {
panic(err)
}
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
gs.Logger().Info("Connected to the server")
<-done
gs.Close()
}
func setupLogging() logr.Logger {
zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMs
zerologr.NameFieldName = "logger"
zerologr.NameSeparator = "/"
zerologr.SetMaxV(1)
zl := zerolog.New(os.Stderr)
zl = zl.With().Caller().Timestamp().Logger()
return zerologr.New(&zl)
}