Manager: show error when there was an error loading configuration

This commit is contained in:
Sybren A. Stüvel 2022-03-11 10:51:22 +01:00
parent 850678f495
commit b33db33d17
2 changed files with 12 additions and 1 deletions

View File

@ -61,7 +61,10 @@ func main() {
// Load configuration. // Load configuration.
configService := config.NewService() configService := config.NewService()
configService.Load() err := configService.Load()
if err != nil {
log.Error().Err(err).Msg("loading configuration")
}
// TODO: enable TLS via Let's Encrypt. // TODO: enable TLS via Let's Encrypt.
listen := configService.Get().Listen listen := configService.Get().Listen

View File

@ -12,6 +12,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
) )
@ -191,6 +192,13 @@ func loadConf(filename string) (Conf, error) {
log.Info().Str("file", filename).Msg("loading configuration") log.Info().Str("file", filename).Msg("loading configuration")
yamlFile, err := os.ReadFile(filename) yamlFile, err := os.ReadFile(filename)
if err != nil { if err != nil {
var level zerolog.Level
if os.IsNotExist(err) {
level = zerolog.DebugLevel
} else {
level = zerolog.WarnLevel
}
log.WithLevel(level).Err(err).Msg("unable to load configuration, using defaults")
return DefaultConfig(), err return DefaultConfig(), err
} }