Fix startup failure when home directory doesn't exist
This commit is contained in:
parent
6bf4b28902
commit
7f351e0874
1 changed files with 3 additions and 6 deletions
|
|
@ -75,15 +75,12 @@ func initConfig() {
|
|||
// Use config file from the flag
|
||||
viper.SetConfigFile(cfgFile)
|
||||
} else {
|
||||
// Find home directory
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
// Search for config in home directory if available
|
||||
if home, err := os.UserHomeDir(); err == nil {
|
||||
viper.AddConfigPath(home)
|
||||
}
|
||||
|
||||
// Search config in home directory with name "mbmd" (without extension).
|
||||
viper.AddConfigPath(home)
|
||||
viper.AddConfigPath(".") // optionally look for config in the working directory
|
||||
viper.AddConfigPath("/etc") // path to look for the config file in
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue