-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
59 lines (48 loc) · 1.1 KB
/
Copy pathmain.go
File metadata and controls
59 lines (48 loc) · 1.1 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
package main
import (
"log"
"os"
"os/signal"
"github.com/tuffnerdstuff/hauk-snitch/config"
"github.com/tuffnerdstuff/hauk-snitch/hauk"
m "github.com/tuffnerdstuff/hauk-snitch/mapper"
"github.com/tuffnerdstuff/hauk-snitch/mqtt"
"github.com/tuffnerdstuff/hauk-snitch/notification"
)
var mqttClient *mqtt.Client
var haukClient hauk.Client
var notifier notification.Notifier
var mapper m.Mapper
func main() {
handleInterrupt()
config.LoadConfig()
initHaukClient()
initMqttClient()
initNotifier()
initMapper()
}
func handleInterrupt() {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, os.Kill)
go func() {
<-interrupt
log.Println("Exiting")
if mqttClient != nil {
mqttClient.Disconnect()
}
}()
}
func initMqttClient() {
mqttClient = mqtt.New(config.GetMqttConfig())
mqttClient.Connect()
}
func initHaukClient() {
haukClient = hauk.New(config.GetHaukConfig())
}
func initNotifier() {
notifier = notification.New(config.GetNotificationConfig())
}
func initMapper() {
mapper = m.New(config.GetMapperConfig(), haukClient, notifier)
mapper.Run(mqttClient.Messages)
}