From 3a6f45fac2eac75b9f39e206695654f8a0cbc14b Mon Sep 17 00:00:00 2001 From: andig Date: Fri, 8 Dec 2023 18:19:53 +0100 Subject: [PATCH] Revert "chore: simplify getting configuration from env" This reverts commit 4b5435b080e6eacf30d556cb753c8d3861f63987. --- cmd/root.go | 9 +++++++++ go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index f43271f4d8..cb1cafeff0 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -22,10 +22,13 @@ 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" _ "github.com/joho/godotenv/autoload" "github.com/prometheus/client_golang/prometheus/promhttp" "github.com/spf13/cobra" "github.com/spf13/viper" + "golang.org/x/exp/maps" ) const rebootDelay = 5 * time.Minute // delayed reboot on error @@ -90,6 +93,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()) diff --git a/go.mod b/go.mod index 7887f3d3ad..b6d0904222 100644 --- a/go.mod +++ b/go.mod @@ -84,7 +84,7 @@ require ( github.com/spf13/cobra v1.8.0 github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/pflag v1.0.5 - github.com/spf13/viper v1.18.1 + github.com/spf13/viper v1.17.0 github.com/stretchr/testify v1.8.4 github.com/traefik/yaegi v0.15.1 github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c diff --git a/go.sum b/go.sum index b5f4941194..3c5cf948f0 100644 --- a/go.sum +++ b/go.sum @@ -646,8 +646,8 @@ github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0 github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= -github.com/spf13/viper v1.18.1 h1:rmuU42rScKWlhhJDyXZRKJQHXFX02chSVW1IvkPGiVM= -github.com/spf13/viper v1.18.1/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= +github.com/spf13/viper v1.17.0 h1:I5txKw7MJasPL/BrfkbA0Jyo/oELqVmux4pR/UxOMfI= +github.com/spf13/viper v1.17.0/go.mod h1:BmMMMLQXSbcHK6KAOiFLz0l5JHrU89OdIRHvsk0+yVI= github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0= github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw= github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=