Fix viper configurations
This commit is contained in:
parent
0645bc876c
commit
593c56d91a
@ -19,6 +19,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -58,6 +59,7 @@ func initConfig() {
|
|||||||
viper.SetConfigName("lasso")
|
viper.SetConfigName("lasso")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||||
viper.SetEnvPrefix("lasso")
|
viper.SetEnvPrefix("lasso")
|
||||||
viper.AutomaticEnv() // Read in environment variables that match
|
viper.AutomaticEnv() // Read in environment variables that match
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"strings"
|
||||||
|
|
||||||
"github.com/abiosoft/ishell"
|
"github.com/abiosoft/ishell"
|
||||||
"github.com/mitchellh/mapstructure"
|
"github.com/mitchellh/mapstructure"
|
||||||
@ -57,17 +57,12 @@ func initConfig() {
|
|||||||
// Use config file from the flag.
|
// Use config file from the flag.
|
||||||
viper.SetConfigFile(cfgFile)
|
viper.SetConfigFile(cfgFile)
|
||||||
} else {
|
} else {
|
||||||
// Find home directory.
|
viper.SetConfigType("/etc")
|
||||||
home, err := os.UserHomeDir()
|
|
||||||
cobra.CheckErr(err)
|
|
||||||
|
|
||||||
// Search config in home directory with name ".lassoctl" (without extension).
|
|
||||||
viper.AddConfigPath(".")
|
|
||||||
viper.AddConfigPath(home)
|
|
||||||
viper.SetConfigType("toml")
|
|
||||||
viper.SetConfigName("lassoctl")
|
viper.SetConfigName("lassoctl")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
viper.SetEnvPrefix("lassoctl")
|
||||||
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||||
viper.AutomaticEnv() // read in environment variables that match
|
viper.AutomaticEnv() // read in environment variables that match
|
||||||
|
|
||||||
// If a config file is found, read it in.
|
// If a config file is found, read it in.
|
||||||
|
Loading…
Reference in New Issue
Block a user