25 lines
536 B
Go
25 lines
536 B
Go
package ssh
|
|
|
|
import (
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
// ConnectFunc is a convenience method for returning a function
|
|
// that just uses net.Dial to communicate with the remote end that
|
|
// is suitable for use with the SSH communicator configuration.
|
|
func ConnectFunc(network, addr string) func() (net.Conn, error) {
|
|
return func() (net.Conn, error) {
|
|
c, err := net.DialTimeout(network, addr, 15*time.Second)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
if tcpConn, ok := c.(*net.TCPConn); ok {
|
|
tcpConn.SetKeepAlive(true)
|
|
}
|
|
|
|
return c, nil
|
|
}
|
|
}
|