Skip to content

Commit

Permalink
Added an optional local port definition (#4)
Browse files Browse the repository at this point in the history
This commit simply adds the support for a local port definition when creating a tunnel.
  • Loading branch information
rnsc authored and elliotchance committed Jan 15, 2020
1 parent 4f4fabd commit 52c7403
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions ssh_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 52c7403

Please sign in to comment.