Register all known config elements as ENV keys

This commit is contained in:
andig 2023-02-19 15:27:19 +01:00
parent 656babbd79
commit c65f7270a9

View file

@ -21,6 +21,9 @@ import (
"github.com/evcc-io/evcc/util/pipe"
"github.com/evcc-io/evcc/util/sponsor"
"github.com/evcc-io/evcc/util/telemetry"
"github.com/fatih/structs"
"github.com/jeremywohl/flatten"
"golang.org/x/exp/maps"
_ "github.com/joho/godotenv/autoload"
"github.com/prometheus/client_golang/prometheus/promhttp"
@ -89,6 +92,12 @@ func initConfig() {
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv() // read in environment variables that match
// register all known config keys
flat, _ := flatten.Flatten(structs.Map(conf), "", flatten.DotStyle)
for _, v := range maps.Keys(flat) {
viper.BindEnv(v)
}
// print version
util.LogLevel("info", nil)
log.INFO.Printf("evcc %s", server.FormattedVersion())