diff --git a/config/tomlloader.go b/config/tomlloader.go index 172b7dd1..64e06761 100644 --- a/config/tomlloader.go +++ b/config/tomlloader.go @@ -61,9 +61,14 @@ func (c TOMLLoader) Load(pathToToml, keyPass, sudoPass string) (err error) { } s := ServerInfo{ServerName: name} - s.User = v.User - if s.User == "" { + + switch { + case v.User != "": + s.User = v.User + case d.User != "": s.User = d.User + default: + return fmt.Errorf("%s is invalid. User is empty", name) } // s.Password = sudoPass @@ -73,10 +78,17 @@ func (c TOMLLoader) Load(pathToToml, keyPass, sudoPass string) (err error) { } s.Host = v.Host + if s.Host == "" { + return fmt.Errorf("%s is invalid. host is empty", name) + } - s.Port = v.Port - if s.Port == "" { + switch { + case v.Port != "": + s.Port = v.Port + case d.Port != "": s.Port = d.Port + default: + s.Port = "22" } s.KeyPath = v.KeyPath @@ -86,7 +98,7 @@ func (c TOMLLoader) Load(pathToToml, keyPass, sudoPass string) (err error) { if s.KeyPath != "" { if _, err := os.Stat(s.KeyPath); err != nil { return fmt.Errorf( - "config.toml is invalid. keypath: %s not exists", s.KeyPath) + "%s is invalid. keypath: %s not exists", name, s.KeyPath) } }