Skip to content

Commit 9c6e287

Browse files
author
David Pinheiro
committed
Fix documentation
1 parent 728044f commit 9c6e287

File tree

4 files changed

+48
-48
lines changed

4 files changed

+48
-48
lines changed

tunnel/config.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
log "github.com/sirupsen/logrus"
1111
)
1212

13-
//Resolver finds specific attributes of a ssh server configured on a ssh config
14-
//file.
13+
// Resolver finds specific attributes of a ssh server configured on a ssh config
14+
// file.
1515
type Resolver struct {
1616
sshConfig *ssh_config.Config
1717
}
1818

19-
//NewResolver creates a new instance of Resolver based on the given ssh config
20-
//file path.
19+
// NewResolver creates a new instance of Resolver based on the given ssh config
20+
// file path.
2121
func NewResolver(configPath string) (*Resolver, error) {
2222
f, err := os.Open(filepath.Clean(configPath))
2323
if err != nil {
@@ -34,9 +34,9 @@ func NewResolver(configPath string) (*Resolver, error) {
3434
return &Resolver{sshConfig: cfg}, nil
3535
}
3636

37-
//Resolve consults a ssh config file to extract some ssh server attributes from
38-
//it, returning a ResolvedHost. Any attribute which its value is an empty
39-
//string is an attribute that could not be found in the ssh config file.
37+
// Resolve consults a ssh config file to extract some ssh server attributes
38+
// from it, returning a ResolvedHost. Any attribute which its value is an empty
39+
// string is an attribute that could not be found in the ssh config file.
4040
func (r Resolver) Resolve(host string) *ResolvedHost {
4141
hostname := r.resolveHostname(host)
4242

@@ -92,15 +92,15 @@ func (r Resolver) resolveKey(host string) string {
9292
return ""
9393
}
9494

95-
//ResolvedHost holds information extracted from a ssh config file.
95+
// ResolvedHost holds information extracted from a ssh config file.
9696
type ResolvedHost struct {
9797
Hostname string
9898
Port string
9999
User string
100100
Key string
101101
}
102102

103-
//String returns a string representation of a ResolvedHost.
103+
// String returns a string representation of a ResolvedHost.
104104
func (rh ResolvedHost) String() string {
105105
return fmt.Sprintf("[hostname=%s, port=%s, user=%s, key=%s]", rh.Hostname, rh.Port, rh.User, rh.Key)
106106
}

tunnel/doc.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
tunnel provides APIs to create SSH tunnels to perform local port forwarding,
3-
leveraging the SSH configuration file (e.g. $HOME/.ssh/config) to find
4-
specific attributes of the target ssh server like user name, port, host name
5-
and key when not provided.
2+
Package tunnel provides APIs to create SSH tunnels to perform local port
3+
forwarding, leveraging the SSH configuration file (e.g. $HOME/.ssh/config) to
4+
find specific attributes of the target ssh server like user name, port, host
5+
name and key when not provided.
66
77
SSH Config File Support
88

tunnel/tunnel.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ import (
1515
"golang.org/x/crypto/ssh/knownhosts"
1616
)
1717

18-
//Server holds the SSH Server attributes used for the client to connect to it.
18+
// Server holds the SSH Server attributes used for the client to connect to it.
1919
type Server struct {
2020
Name string
2121
Address string
2222
User string
2323
Key string
2424
}
2525

26-
//NewServer creates a new instance of Server using $HOME/.ssh/config to resolve
27-
//the missing connection attributes (e.g. user, hostname, port and key)
28-
//required to connect to the remote server, if any.
26+
// NewServer creates a new instance of Server using $HOME/.ssh/config to
27+
// resolve the missing connection attributes (e.g. user, hostname, port and
28+
// key) required to connect to the remote server, if any.
2929
func NewServer(user, address, key string) (*Server, error) {
3030
var host string
3131
var hostname string
@@ -86,21 +86,21 @@ func NewServer(user, address, key string) (*Server, error) {
8686
}, nil
8787
}
8888

89-
//String provided a string representation os a Server.
89+
// String provided a string representation os a Server.
9090
func (s Server) String() string {
9191
return fmt.Sprintf("[name=%s, address=%s, user=%s, key=%s]", s.Name, s.Address, s.User, s.Key)
9292
}
9393

94-
//Tunnel represents the ssh tunnel used to forward a local connection to a
95-
//a remote endpoint through a ssh server.
94+
// Tunnel represents the ssh tunnel used to forward a local connection to a
95+
// a remote endpoint through a ssh server.
9696
type Tunnel struct {
9797
local string
9898
server *Server
9999
remote string
100100
done chan error
101101
}
102102

103-
//New creates a new instance of Tunnel
103+
// New creates a new instance of Tunnel.
104104
func New(localAddress string, server *Server, remoteAddress string) *Tunnel {
105105

106106
if localAddress == "" {
@@ -115,8 +115,8 @@ func New(localAddress string, server *Server, remoteAddress string) *Tunnel {
115115
}
116116
}
117117

118-
//Start creates a new ssh tunnel, allowing data exchange between the local and
119-
//remote endpoints.
118+
// Start creates a new ssh tunnel, allowing data exchange between the local and
119+
// remote endpoints.
120120
func (t *Tunnel) Start() error {
121121
local, err := net.Listen("tcp", t.local)
122122
if err != nil {
@@ -170,12 +170,12 @@ func (t *Tunnel) forward(localConn net.Conn) error {
170170
return nil
171171
}
172172

173-
//Stop cancels the tunnel, closing all connections.
173+
// Stop cancels the tunnel, closing all connections.
174174
func (t Tunnel) Stop() {
175175
t.done <- nil
176176
}
177177

178-
//String returns a string representation of a Tunnel.
178+
// String returns a string representation of a Tunnel.
179179
func (t Tunnel) String() string {
180180
return fmt.Sprintf("[local:%s, server:%s, remote:%s]", t.local, t.server.Address, t.remote)
181181
}

tunnel/tunnel_test.go

+23-23
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ func TestMain(m *testing.M) {
126126
os.Exit(code)
127127
}
128128

129-
//prepareTunnel creates a Tunnel object making sure all infrastructure
130-
//dependencies (ssh and http servers) are ready returning a connection that
131-
//can be use to reach the remote http server through the tunnel.
129+
// prepareTunnel creates a Tunnel object making sure all infrastructure
130+
// dependencies (ssh and http servers) are ready returning a connection that
131+
// can be use to reach the remote http server through the tunnel.
132132
func prepareTunnel(t *testing.T) net.Conn {
133133
sshAddr := createSSHServer(keyPath)
134134
generateKnownHosts(sshAddr.String(), publicKeyPath, knownHostsPath)
@@ -191,8 +191,8 @@ func prepareTestEnv() {
191191
os.Setenv("HOME", home)
192192
}
193193

194-
//newHttpClient create an http client that will always use the given connection
195-
//to perform http requests.
194+
// newHttpClient create an http client that will always use the given
195+
// connection to perform http requests.
196196
func newHttpClient(conn net.Conn) http.Client {
197197
tr := &http.Transport{
198198
Dial: func(network, address string) (net.Conn, error) {
@@ -208,11 +208,11 @@ func newHttpClient(conn net.Conn) http.Client {
208208
return client
209209
}
210210

211-
//get performs a http request using the given client appending the given
212-
//resource to to a hard-coded URL.
211+
// get performs a http request using the given client appending the given
212+
// resource to to a hard-coded URL.
213213
//
214-
//The request performed by this function is designed to reach the other side
215-
//through a pipe (net.Pipe()) and this is the reason the URL is hard-coded.
214+
// The request performed by this function is designed to reach the other side
215+
// through a pipe (net.Pipe()) and this is the reason the URL is hard-coded.
216216
func get(client http.Client, resource string) (string, error) {
217217
resp, err := client.Get(fmt.Sprintf("%s%s", "http://any-url-is.fine", resource))
218218
if err != nil {
@@ -225,11 +225,11 @@ func get(client http.Client, resource string) (string, error) {
225225
return string(body), nil
226226
}
227227

228-
//createWebServer spawns a new http server, listening on a random user port and
229-
//providing a response identical to the resource provided by the request.
228+
// createWebServer spawns a new http server, listening on a random user port
229+
// and providing a response identical to the resource provided by the request.
230230
//
231-
//Example: If the request URI is /this-is-a-test, the response will be
232-
//this-is-a-test
231+
// Example: If the request URI is /this-is-a-test, the response will be
232+
// this-is-a-test
233233
func createWebServer() net.Addr {
234234

235235
handler := func(w http.ResponseWriter, r *http.Request) {
@@ -245,16 +245,16 @@ func createWebServer() net.Addr {
245245
return l.Addr()
246246
}
247247

248-
//createSSHServer starts a SSH server that authenticates connections using
249-
//the given keyPath, listens on a random user port and returns the SSH Server
250-
//address.
248+
// createSSHServer starts a SSH server that authenticates connections using
249+
// the given keyPath, listens on a random user port and returns the SSH Server
250+
// address.
251251
//
252-
//The SSH Server created by this function only responds to "direct-tcpip",
253-
//which is used to establish local port forwarding.
252+
// The SSH Server created by this function only responds to "direct-tcpip",
253+
// which is used to establish local port forwarding.
254254
//
255-
//References:
256-
//https://gist.github.com/jpillora/b480fde82bff51a06238
257-
//https://tools.ietf.org/html/rfc4254#section-7.2
255+
// References:
256+
// https://gist.github.com/jpillora/b480fde82bff51a06238
257+
// https://tools.ietf.org/html/rfc4254#section-7.2
258258
func createSSHServer(keyPath string) net.Addr {
259259
conf := &ssh.ServerConfig{
260260
PublicKeyCallback: func(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
@@ -309,8 +309,8 @@ func createSSHServer(keyPath string) net.Addr {
309309
return l.Addr()
310310
}
311311

312-
//generateKnownHosts creates a new "known_hosts" file on a given path with a
313-
//single entry based on the given SSH server address and public key.
312+
// generateKnownHosts creates a new "known_hosts" file on a given path with a
313+
// single entry based on the given SSH server address and public key.
314314
func generateKnownHosts(sshAddr, pubKeyPath, knownHostsPath string) {
315315
i := strings.Split(sshAddr, ":")[0]
316316
p := strings.Split(sshAddr, ":")[1]

0 commit comments

Comments
 (0)