Update to make non existing config a soft error

This commit is contained in:
KemoNine 2020-09-20 18:10:14 -04:00
parent d5a06b79db
commit df886ff66d
5 changed files with 12 additions and 8 deletions

View file

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

View file

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

View file

@ -2,10 +2,10 @@ package main
import (
"log"
"os/exec"
"strconv"
"strings"
"time"
"os/exec"
"git.kemonine.info/PiFrame/config"
)
@ -17,7 +17,7 @@ const (
func main() {
// Load the config file
pfConfig, _ := config.LoadConfig()
pfConfig, _ := config.LoadConfig(false)
pfConfig.Print()
// Read config values

View file

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

View file

@ -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 {
if errFatalOnMissing {
log.Fatalf("Error loading config : %s", err)
} else {
log.Printf("Error loading config : %s", err)
}
}
log.Print("========================================")