From df886ff66de6b37e86ebc78c318bcba0e1421855 Mon Sep 17 00:00:00 2001 From: KemoNine Date: Sun, 20 Sep 2020 18:10:14 -0400 Subject: [PATCH] Update to make non existing config a soft error --- cmd/fan/fan.go | 2 +- cmd/gui/gui.go | 2 +- cmd/hdmi/hdmi.go | 6 +++--- cmd/inotify/inotify.go | 2 +- config/config.go | 8 ++++++-- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cmd/fan/fan.go b/cmd/fan/fan.go index 53f8d26..38d332b 100644 --- a/cmd/fan/fan.go +++ b/cmd/fan/fan.go @@ -20,7 +20,7 @@ const ( func main() { // Load the config file - pfConfig, configFileProvider := config.LoadConfig() + pfConfig, configFileProvider := config.LoadConfig(false) // Watch for config changes and re-load config if needed configFileProvider.Watch(func(event interface{}, err error) { diff --git a/cmd/gui/gui.go b/cmd/gui/gui.go index 973757c..e084b59 100644 --- a/cmd/gui/gui.go +++ b/cmd/gui/gui.go @@ -34,7 +34,7 @@ func main() { log.Print("Loading config") // Load the config file - pfConfig, configFileProvider := config.LoadConfig() + pfConfig, configFileProvider := config.LoadConfig(false) log.Printf("%v", pfConfig) pfConfig.Print() diff --git a/cmd/hdmi/hdmi.go b/cmd/hdmi/hdmi.go index 22a842c..e379577 100644 --- a/cmd/hdmi/hdmi.go +++ b/cmd/hdmi/hdmi.go @@ -2,22 +2,22 @@ package main import ( "log" + "os/exec" "strconv" "strings" "time" - "os/exec" "git.kemonine.info/PiFrame/config" ) const ( - CMD_VCGENCMD = "/opt/vc/bin//vcgencmd" + CMD_VCGENCMD = "/opt/vc/bin//vcgencmd" CMD_VCGENCMD_DISPLAY_POWER = "display_power" ) func main() { // Load the config file - pfConfig, _ := config.LoadConfig() + pfConfig, _ := config.LoadConfig(false) pfConfig.Print() // Read config values diff --git a/cmd/inotify/inotify.go b/cmd/inotify/inotify.go index d148596..e42605b 100644 --- a/cmd/inotify/inotify.go +++ b/cmd/inotify/inotify.go @@ -18,7 +18,7 @@ const ( func main() { // Load the config file - pfConfig, configFileProvider := config.LoadConfig() + pfConfig, configFileProvider := config.LoadConfig(false) // Watch for config changes and re-load config if needed configFileProvider.Watch(func(event interface{}, err error) { diff --git a/config/config.go b/config/config.go index 6e4a88e..450e776 100644 --- a/config/config.go +++ b/config/config.go @@ -9,7 +9,7 @@ import ( kfile "github.com/knadh/koanf/providers/file" ) -func LoadConfig() (*koanf.Koanf, *kfile.File) { +func LoadConfig(errFatalOnMissing bool) (*koanf.Koanf, *kfile.File) { // Main config variable var pfConfig = koanf.New(".") @@ -30,7 +30,11 @@ func LoadConfig() (*koanf.Koanf, *kfile.File) { configFileProvider := kfile.Provider(CONFIG_FILE_PATH) log.Print("========================================") if err := pfConfig.Load(configFileProvider, toml.Parser()); err != nil { - log.Fatalf("Error loading config : %s", err) + if errFatalOnMissing { + log.Fatalf("Error loading config : %s", err) + } else { + log.Printf("Error loading config : %s", err) + } } log.Print("========================================")