summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Anderson <[email protected]>2017-07-05 17:20:03 -0700
committerDavid Anderson <[email protected]>2017-07-05 17:29:29 -0700
commite03035937341374a9be6eb8459ffe4f23bacd185 (patch)
tree76c0b6da00ab091ce63a658d2e20b1235c0cb54c
parent6d97c2aa8ea9d9f5a35614d1f4a2a7d6be28ae9a (diff)
Fix golint nits by adding docstrings and simplifying execution flow.fix-golint
-rw-r--r--listener.go5
-rw-r--r--listener_test.go3
-rw-r--r--tcpproxy.go1
3 files changed, 7 insertions, 2 deletions
diff --git a/listener.go b/listener.go
index 2fd29eb..1ddc48e 100644
--- a/listener.go
+++ b/listener.go
@@ -48,8 +48,12 @@ type tcpAddr string
func (a tcpAddr) Network() string { return "tcp" }
func (a tcpAddr) String() string { return string(a) }
+// Addr returns the listener's Address field as a net.Addr.
func (tl *TargetListener) Addr() net.Addr { return tcpAddr(tl.Address) }
+// Close stops listening for new connections. All new connections
+// routed to this listener will be closed. Already accepted
+// connections are not closed.
func (tl *TargetListener) Close() error {
tl.lock()
if tl.closed {
@@ -85,6 +89,7 @@ func (tl *TargetListener) HandleConn(c net.Conn) {
}
}
+// Accept implements the Accept method in the net.Listener interface.
func (tl *TargetListener) Accept() (net.Conn, error) {
tl.lock()
for tl.nextConn == nil && !tl.closed {
diff --git a/listener_test.go b/listener_test.go
index 35f888e..70087ca 100644
--- a/listener_test.go
+++ b/listener_test.go
@@ -28,9 +28,8 @@ func TestListenerAccept(t *testing.T) {
if err != nil {
ch <- err
return
- } else {
- ch <- conn
}
+ ch <- conn
}
}()
diff --git a/tcpproxy.go b/tcpproxy.go
index 8a520f6..8a316c7 100644
--- a/tcpproxy.go
+++ b/tcpproxy.go
@@ -295,6 +295,7 @@ func UnderlyingConn(c net.Conn) net.Conn {
return c
}
+// HandleConn implements the Target interface.
func (dp *DialProxy) HandleConn(src net.Conn) {
ctx := context.Background()
var cancel context.CancelFunc