melbahja / goph

🤘 The native golang ssh client to execute your commands over ssh connection. 🚀🚀

Home Page:http://git.io/bfpiw

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Making defaultPath evaluation lazy

xxzefgh opened this issue · comments

Would you consider wrapping defaultPath in a function? The issue is on Windows environments HOME is not set by default. Simple solution would be setting it manually when the program starts:

os.Setenv("HOME", os.Getenv("USERPROFILE"))

but it doesn't get recognized by goph since it is evaluated beforehand.

I am using this workaround now:

func getConnection(target DeploymentTarget) (*goph.Client, error) {
	callback, err := goph.KnownHosts(os.ExpandEnv("$HOME/.ssh/known_hosts"))
	if err == nil {
		client, err := goph.NewConn(&goph.Config{
			User:     target.Config.User,
			Addr:     target.Config.Address,
			Port:     22,
			Auth:     goph.Password(target.Config.Password),
			Timeout:  goph.DefaultTimeout,
			Callback: callback,
		})

		if err == nil {
			return client, nil
		}
	}

	return nil, err
}

hi, thanks for your report.
can you check the pull request fix ?

that would probably work but os/user prevents cross-compilation, UserHomeDir is better option but it's fairly new

changed to os UserHomeDir
Thanks :)