From 52c7403b78f0ee987fbd012c2b94956c3a40f5a6 Mon Sep 17 00:00:00 2001 From: rnsc Date: Thu, 16 Jan 2020 00:07:06 +0100 Subject: [PATCH] Added an optional local port definition (#4) This commit simply adds the support for a local port definition when creating a tunnel. --- README.md | 4 ++++ ssh_tunnel.go | 7 ++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 8c11cae..3a44f19 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,10 @@ tunnel := sshtunnel.NewSSHTunnel( // The destination host and port of the actual server. "dqrsdfdssdfx.us-east-1.redshift.amazonaws.com:5439", + + // The local port you want to bind the remote port to. + // Specifying "0" will lead to a random port. + "8443", ) // You can provide a logger for debugging, or remove this line to diff --git a/ssh_tunnel.go b/ssh_tunnel.go index 6d4e7ce..6779b20 100644 --- a/ssh_tunnel.go +++ b/ssh_tunnel.go @@ -83,9 +83,10 @@ func (tunnel *SSHTunnel) Close() { return } -func NewSSHTunnel(tunnel string, auth ssh.AuthMethod, destination string) *SSHTunnel { - // A random port will be chosen for us. - localEndpoint := NewEndpoint("localhost:0") +// NewSSHTunnel creates a new single-use tunnel. Supplying "0" for localport will use a random port. +func NewSSHTunnel(tunnel string, auth ssh.AuthMethod, destination string, localport string) *SSHTunnel { + + localEndpoint := NewEndpoint("localhost:"+localport) server := NewEndpoint(tunnel) if server.Port == 0 {