-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (48 loc) · 1.14 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
/*
* mqtt-quacker
*
*
* Contact: [email protected]
*/
package main
import (
"fmt"
"mqtt-quacker/app"
"os"
"runtime"
)
func main() {
fmt.Printf("Server started\n")
mqttConfig := app.QuackerConfig{
Host: getEnv("QUACKER_HOST", "127.0.0.1"), // "mqtt.osvie.com",
Port: getEnv("QUACKER_PORT", "1883"),
Username: getEnv("QUACKER_USERNAME", ""),
Password: getEnv("QUACKER_PASSWORD", ""),
Topic: getEnvOrFail("QUACKER_TOPIC"),
ClientId: getEnv("QUACKER_CLIENTID", "mqtt-quacker"),
QoS: getEnv("QUACKER_QOS", "0"),
Interval: getEnv("QUACKER_INTERVAL", "1000"),
DataFile: getEnv("QUACKER_DATAFILE", "/data.json"),
DryRun: getEnv("QUACKER_DRYRUN", "") != "",
}
quacker := app.NewQuacker(mqttConfig)
runtime.SetFinalizer(&quacker, func(obj *app.Quacker) {
obj.Close()
})
quacker.Start()
defer quacker.Close()
}
func getEnv(key string, defaultValue string) string {
value, found := os.LookupEnv(key)
if found == false {
return defaultValue
}
return value
}
func getEnvOrFail(key string) string {
value, found := os.LookupEnv(key)
if found == false {
panic("Need env key" + key)
}
return value
}