fix: environment variable parsing

This is more of a workaround than the correct solution. It only fixes top-level ENV variables parsing.
This commit is contained in:
Henrique Dias
2024-07-25 22:46:34 +02:00
committed by GitHub
parent f6a0707fe6
commit 814462bed1
2 changed files with 33 additions and 0 deletions
+11
View File
@@ -11,6 +11,10 @@ import (
)
const (
DefaultScope = "/"
DefaultModify = false
DefaultDebug = false
DefaultNoSniff = false
DefaultTLS = false
DefaultAuth = false
DefaultCert = "cert.pem"
@@ -65,8 +69,15 @@ func ParseConfig(filename string, flags *pflag.FlagSet) (*Config, error) {
v.SetEnvPrefix("wd")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
v.AutomaticEnv()
// TODO: use new env struct bind feature when it's released in viper.
// This should make it redundant to set defaults for things that are
// empty or false.
// Defaults shared with flags
v.SetDefault("Scope", DefaultScope)
v.SetDefault("Modify", DefaultModify)
v.SetDefault("Debug", DefaultDebug)
v.SetDefault("NoSniff", DefaultNoSniff)
v.SetDefault("TLS", DefaultTLS)
v.SetDefault("Cert", DefaultCert)
v.SetDefault("Key", DefaultKey)