config for kiosk handler
This commit is contained in:
parent
f085312e13
commit
85abccf14a
@ -104,10 +104,16 @@ func initConfig() {
|
|||||||
"image_dir",
|
"image_dir",
|
||||||
"version",
|
"version",
|
||||||
"webserver_port",
|
"webserver_port",
|
||||||
|
"mqtt_broker_url",
|
||||||
|
"mqtt_broker_user",
|
||||||
|
"mqtt_broker_password",
|
||||||
|
"mqtt_presence_topic",
|
||||||
|
"kiosk_cmd_screen_on",
|
||||||
|
"kiosk_cmd_screen_off",
|
||||||
}
|
}
|
||||||
for _, key := range expected_config {
|
for _, key := range expected_config {
|
||||||
if !viper.IsSet(key) {
|
if !viper.IsSet(key) {
|
||||||
fmt.Fprintf(os.Stderr, "Missing configuration value: %s\n", key)
|
log.Fatalf("Missing configuration value: %s\n", key)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,6 +14,12 @@ func TestInitConfig(t *testing.T) {
|
|||||||
viper.Set("deployment", "testing")
|
viper.Set("deployment", "testing")
|
||||||
viper.Set("image_dir", "/tmp")
|
viper.Set("image_dir", "/tmp")
|
||||||
viper.Set("webserver_port", "8080")
|
viper.Set("webserver_port", "8080")
|
||||||
|
viper.Set("mqtt_broker_url", "mqtt://example.com:1883")
|
||||||
|
viper.Set("mqtt_broker_user", "testuser")
|
||||||
|
viper.Set("mqtt_broker_password", "testpass")
|
||||||
|
viper.Set("mqtt_presence_topic", "home/foo/test")
|
||||||
|
viper.Set("kiosk_cmd_screen_on", "echo screen on")
|
||||||
|
viper.Set("kiosk_cmd_screen_off", "echo screen off")
|
||||||
|
|
||||||
initConfig()
|
initConfig()
|
||||||
assert.Equal(t, gitVersion, viper.GetString("version"), "config version mismatch")
|
assert.Equal(t, gitVersion, viper.GetString("version"), "config version mismatch")
|
||||||
@ -25,6 +31,12 @@ func TestInitConfigMissingImageDir(t *testing.T) {
|
|||||||
viper.Set("deployment", "testing")
|
viper.Set("deployment", "testing")
|
||||||
viper.Set("version", "vTest")
|
viper.Set("version", "vTest")
|
||||||
viper.Set("webserver_port", "8080")
|
viper.Set("webserver_port", "8080")
|
||||||
|
viper.Set("mqtt_broker_url", "mqtt://example.com:1883")
|
||||||
|
viper.Set("mqtt_broker_user", "testuser")
|
||||||
|
viper.Set("mqtt_broker_password", "testpass")
|
||||||
|
viper.Set("mqtt_presence_topic", "home/foo/test")
|
||||||
|
viper.Set("kiosk_cmd_screen_on", "echo screen on")
|
||||||
|
viper.Set("kiosk_cmd_screen_off", "echo screen off")
|
||||||
|
|
||||||
initConfig()
|
initConfig()
|
||||||
return
|
return
|
||||||
|
|||||||
@ -15,6 +15,8 @@ type configObj struct {
|
|||||||
username string
|
username string
|
||||||
password string
|
password string
|
||||||
presenceTopic string
|
presenceTopic string
|
||||||
|
screen_on_cmd string
|
||||||
|
screen_off_cmd string
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = configObj{}
|
var config = configObj{}
|
||||||
@ -25,6 +27,8 @@ func Run(rootLogger *slog.Logger, exitch chan bool, ctx context.Context) {
|
|||||||
config.username = viper.GetString("mqtt_broker_user")
|
config.username = viper.GetString("mqtt_broker_user")
|
||||||
config.password = viper.GetString("mqtt_broker_password")
|
config.password = viper.GetString("mqtt_broker_password")
|
||||||
config.presenceTopic = viper.GetString("mqtt_presence_topic")
|
config.presenceTopic = viper.GetString("mqtt_presence_topic")
|
||||||
|
config.screen_on_cmd = viper.GetString("kiosk_cmd_screen_on")
|
||||||
|
config.screen_off_cmd = viper.GetString("kiosk_cmd_screen_off")
|
||||||
config.logger.Info("starting MQTT broker client")
|
config.logger.Info("starting MQTT broker client")
|
||||||
brokerConsume(ctx)
|
brokerConsume(ctx)
|
||||||
exitch <- true
|
exitch <- true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user