-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (42 loc) · 1.09 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
package main
import (
"github.com/spf13/viper"
"log"
"os"
"os/signal"
"strings"
"syscall"
)
func configure() {
viper.SetConfigName("x32-mqtt")
viper.SetConfigType("yaml")
viper.AddConfigPath(".")
viper.AddConfigPath("/etc/x32-mqtt")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()
// OSC Configuration
viper.SetDefault("osc.host", "localhost")
viper.SetDefault("osc.port", 1234)
// MQTT Configuration
viper.SetDefault("mqtt.broker", "localhost:1883")
viper.SetDefault("mqtt.username", "")
viper.SetDefault("mqtt.password", "")
viper.SetDefault("mqtt.client_id", "osc-mqtt")
viper.SetDefault("mqtt.keep_alive", "300s")
viper.SetDefault("topic_prefix", "sound")
if err := viper.ReadInConfig(); err != nil {
log.Println(err)
_ = viper.SafeWriteConfig()
log.Println("Running with default config...")
}
}
func main() {
configure()
log.Println("Starting x32-mqtt")
setupMQTTClient()
setupOSCClient()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
<-sigChan
log.Println("Exiting...")
}