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