Allow configuration by environment
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
Søren Rasmussen 2024-06-15 22:49:09 +02:00
parent 38b4e0abdc
commit 4ef93fb6cf

View file

@ -4,6 +4,7 @@ import (
"bytes"
_ "embed"
"log"
"strings"
"sync"
"github.com/getsentry/sentry-go"
@ -32,7 +33,8 @@ func Global() Configuration {
func Initialize() {
setDefaults()
viper.SetConfigName("fermentord")
viper.SetConfigType("toml")
viper.SetEnvPrefix("fermentord")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "__"))
}
func LoadConfiguration() Configuration {
@ -48,6 +50,8 @@ func LoadConfiguration() Configuration {
log.Printf("Error loading configuration: %v", err)
}
viper.AutomaticEnv()
config := Configuration{}
if err := viper.Unmarshal(&config); err != nil {
sentry.CaptureException(err)