Browse Source

Update to make non existing config a soft error

master
KemoNine 2 years ago
parent
commit
df886ff66d
  1. 2
      cmd/fan/fan.go
  2. 2
      cmd/gui/gui.go
  3. 6
      cmd/hdmi/hdmi.go
  4. 2
      cmd/inotify/inotify.go
  5. 8
      config/config.go

2
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) {

2
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()

6
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

2
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) {

8
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("========================================")

Loading…
Cancel
Save