diff --git a/util/config.go b/util/config.go index faf85197..e4786984 100644 --- a/util/config.go +++ b/util/config.go @@ -157,30 +157,19 @@ func loadConfig(){ //If the confPath option has been set try to load and decode it if confPath != nil && len(*confPath) > 0 { file, err := os.Open(*confPath) - if err != nil { - panic(err) - } + exitOnConfigError(err) decodeConfig(file) } else { - // if no confPath look in the cwd cwd, err := os.Getwd() + exitOnConfigError(err) cwd = cwd+"/config.json" confPath = &cwd - if err == nil { - file, err := os.Open(*confPath) - if err == nil { - decodeConfig(file) - } - } - if err != nil { - fmt.Println("Cannot Find configuration! Use -c parameter to point to a JSON file generated by -setup.\n\n Hint: have you run `-setup` ?") - os.Exit(1) - } - + file, err := os.Open(*confPath) + exitOnConfigError(err) + decodeConfig(file) } fmt.Println("Using config file: "+ *confPath) - } func validateConfig(){ @@ -210,6 +199,13 @@ func validatePort() { } } +func exitOnConfigError(err error){ + if err != nil { + fmt.Println("Cannot Find configuration! Use -c parameter to point to a JSON file generated by -setup.\n\n Hint: have you run `-setup` ?") + os.Exit(1) + } +} + func decodeConfig(file *os.File){