From e03035937341374a9be6eb8459ffe4f23bacd185 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 5 Jul 2017 17:20:03 -0700 Subject: Fix golint nits by adding docstrings and simplifying execution flow. --- listener.go | 5 +++++ listener_test.go | 3 +-- tcpproxy.go | 1 + 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 -- cgit v1.2.3