bugfix for error scopes in config checking

This commit is contained in:
Tom Whiston 2018-03-26 11:58:06 +00:00
parent 8bb45c2970
commit 0316fbc607

View File

@ -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){