config := goshen.NewSshConfig("~/.ssh/config")
Once you've created an instance of an SSH config, you can search for hosts using the MatchHost
method.
Sample SSH config
Host server-1
HostName server-1.example.com
User user
Port 22
IdentityFile ~/.ssh/example_rsa
LogLevel FATAL
Host server-2*
HostName server-2.example.com
User user
Port 22
IdentityFile ~/.ssh/example_rsa
LogLevel FATAL
// return the config for server-2 with searching for server-2-web
hostEntry := config.MatchHost("server-2-web")
fmt.Println(hostEntry.HostName) // server-2.example.com
Calling save on the config instance will write the configuration to disk. If the outputPath
argument is an empty string, the path given
at the time goshen.NewSshConfig
was called is used.
outputPath := ""
config.Save(outputPath)