Skip to content

Commit 0a52a47

Browse files
committed
fix some linting issues (errCheck, misspell, unconvert)
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 83a13b4 commit 0a52a47

File tree

12 files changed

+50
-50
lines changed

12 files changed

+50
-50
lines changed

nat/nat.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,17 +153,17 @@ type PortMapping struct {
153153
func splitParts(rawport string) (string, string, string) {
154154
parts := strings.Split(rawport, ":")
155155
n := len(parts)
156-
containerport := parts[n-1]
156+
containerPort := parts[n-1]
157157

158158
switch n {
159159
case 1:
160-
return "", "", containerport
160+
return "", "", containerPort
161161
case 2:
162-
return "", parts[0], containerport
162+
return "", parts[0], containerPort
163163
case 3:
164-
return parts[0], parts[1], containerport
164+
return parts[0], parts[1], containerPort
165165
default:
166-
return strings.Join(parts[:n-2], ":"), parts[n-2], containerport
166+
return strings.Join(parts[:n-2], ":"), parts[n-2], containerPort
167167
}
168168
}
169169

nat/nat_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,12 @@ func TestPort(t *testing.T) {
115115
t.Fatal("port int value was not 1234")
116116
}
117117

118-
p, err = NewPort("tcp", "asd1234")
118+
_, err = NewPort("tcp", "asd1234")
119119
if err == nil {
120120
t.Fatal("tcp, asd1234 was supposed to fail")
121121
}
122122

123-
p, err = NewPort("tcp", "1234-1230")
123+
_, err = NewPort("tcp", "1234-1230")
124124
if err == nil {
125125
t.Fatal("tcp, 1234-1230 was supposed to fail")
126126
}

nat/sort.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type portMapSorter []portMapEntry
4343
func (s portMapSorter) Len() int { return len(s) }
4444
func (s portMapSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
4545

46-
// sort the port so that the order is:
46+
// Less sorts the port so that the order is:
4747
// 1. port with larger specified bindings
4848
// 2. larger port
4949
// 3. port with tcp protocol

nat/sort_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ func TestSortPortMap(t *testing.T) {
7070

7171
SortPortMap(ports, portMap)
7272
if !reflect.DeepEqual(ports, []Port{
73-
Port("9999/tcp"),
74-
Port("6379/tcp"),
75-
Port("8443/tcp"),
76-
Port("8000/tcp"),
77-
Port("22/tcp"),
78-
Port("22/udp"),
73+
"9999/tcp",
74+
"6379/tcp",
75+
"8443/tcp",
76+
"8000/tcp",
77+
"22/tcp",
78+
"22/udp",
7979
}) {
8080
t.Errorf("failed to prioritize port with explicit mappings, got %v", ports)
8181
}

proxy/network_proxy_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (server *TCPEchoServer) Run() {
6565
}
6666

6767
func (server *TCPEchoServer) LocalAddr() net.Addr { return server.listener.Addr() }
68-
func (server *TCPEchoServer) Close() { server.listener.Close() }
68+
func (server *TCPEchoServer) Close() { _ = server.listener.Close() }
6969

7070
func (server *UDPEchoServer) Run() {
7171
go func() {
@@ -87,7 +87,7 @@ func (server *UDPEchoServer) Run() {
8787
}
8888

8989
func (server *UDPEchoServer) LocalAddr() net.Addr { return server.conn.LocalAddr() }
90-
func (server *UDPEchoServer) Close() { server.conn.Close() }
90+
func (server *UDPEchoServer) Close() { _ = server.conn.Close() }
9191

9292
func testProxyAt(t *testing.T, proto string, proxy Proxy, addr string) {
9393
defer proxy.Close()
@@ -97,7 +97,7 @@ func testProxyAt(t *testing.T, proto string, proxy Proxy, addr string) {
9797
t.Fatalf("Can't connect to the proxy: %v", err)
9898
}
9999
defer client.Close()
100-
client.SetDeadline(time.Now().Add(10 * time.Second))
100+
_ = client.SetDeadline(time.Now().Add(10 * time.Second))
101101
if _, err = client.Write(testBuf); err != nil {
102102
t.Fatal(err)
103103
}
@@ -197,12 +197,12 @@ func TestUDPWriteError(t *testing.T) {
197197
}
198198
defer client.Close()
199199
// Make sure the proxy doesn't stop when there is no actual backend:
200-
client.Write(testBuf)
201-
client.Write(testBuf)
200+
_, _ = client.Write(testBuf)
201+
_, _ = client.Write(testBuf)
202202
backend := NewEchoServer(t, "udp", "127.0.0.1:25587")
203203
defer backend.Close()
204204
backend.Run()
205-
client.SetDeadline(time.Now().Add(10 * time.Second))
205+
_ = client.SetDeadline(time.Now().Add(10 * time.Second))
206206
if _, err = client.Write(testBuf); err != nil {
207207
t.Fatal(err)
208208
}

proxy/tcp_proxy.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
4141
backend, err := net.DialTCP("tcp", nil, proxy.backendAddr)
4242
if err != nil {
4343
proxy.Logger.Printf("Can't forward traffic to backend tcp/%v: %s\n", proxy.backendAddr, err)
44-
client.Close()
44+
_ = client.Close()
4545
return
4646
}
4747

@@ -52,10 +52,10 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
5252
// If the socket we are writing to is shutdown with
5353
// SHUT_WR, forward it to the other end of the pipe:
5454
if err, ok := err.(*net.OpError); ok && err.Err == syscall.EPIPE {
55-
from.CloseWrite()
55+
_ = from.CloseWrite()
5656
}
5757
}
58-
to.CloseRead()
58+
_ = to.CloseRead()
5959
event <- written
6060
}
6161

@@ -69,16 +69,16 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
6969
transferred += written
7070
case <-quit:
7171
// Interrupt the two brokers and "join" them.
72-
client.Close()
73-
backend.Close()
72+
_ = client.Close()
73+
_ = backend.Close()
7474
for ; i < 2; i++ {
7575
transferred += <-event
7676
}
7777
return
7878
}
7979
}
80-
client.Close()
81-
backend.Close()
80+
_ = client.Close()
81+
_ = backend.Close()
8282
}
8383

8484
// Run starts forwarding the traffic using TCP.
@@ -96,7 +96,7 @@ func (proxy *TCPProxy) Run() {
9696
}
9797

9898
// Close stops forwarding the traffic.
99-
func (proxy *TCPProxy) Close() { proxy.listener.Close() }
99+
func (proxy *TCPProxy) Close() { _ = proxy.listener.Close() }
100100

101101
// FrontendAddr returns the TCP address on which the proxy is listening.
102102
func (proxy *TCPProxy) FrontendAddr() net.Addr { return proxy.frontendAddr }

proxy/udp_proxy.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ func (proxy *UDPProxy) replyLoop(proxyConn *net.UDPConn, clientAddr *net.UDPAddr
8080
proxy.connTrackLock.Lock()
8181
delete(proxy.connTrackTable, *clientKey)
8282
proxy.connTrackLock.Unlock()
83-
proxyConn.Close()
83+
_ = proxyConn.Close()
8484
}()
8585

8686
readBuf := make([]byte, UDPBufSize)
8787
for {
88-
proxyConn.SetReadDeadline(time.Now().Add(UDPConnTrackTimeout))
88+
_ = proxyConn.SetReadDeadline(time.Now().Add(UDPConnTrackTimeout))
8989
again:
9090
read, err := proxyConn.Read(readBuf)
9191
if err != nil {
@@ -151,11 +151,11 @@ func (proxy *UDPProxy) Run() {
151151

152152
// Close stops forwarding the traffic.
153153
func (proxy *UDPProxy) Close() {
154-
proxy.listener.Close()
154+
_ = proxy.listener.Close()
155155
proxy.connTrackLock.Lock()
156156
defer proxy.connTrackLock.Unlock()
157157
for _, conn := range proxy.connTrackTable {
158-
conn.Close()
158+
_ = conn.Close()
159159
}
160160
}
161161

sockets/inmem_socket_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func TestInmemSocket(t *testing.T) {
1111
if err != nil {
1212
return
1313
}
14-
conn.Write([]byte("hello"))
15-
conn.Close()
14+
_, _ = conn.Write([]byte("hello"))
15+
_ = conn.Close()
1616
}
1717
}()
1818

@@ -31,8 +31,8 @@ func TestInmemSocket(t *testing.T) {
3131
t.Fatalf("expected `hello`, got %s", string(buf))
3232
}
3333

34-
l.Close()
35-
conn, err = l.Dial("test", "test")
34+
_ = l.Close()
35+
_, err = l.Dial("test", "test")
3636
if err != errClosed {
3737
t.Fatalf("expected `errClosed` error, got %v", err)
3838
}

sockets/unix_socket.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func NewUnixSocketWithOpts(path string, opts ...SockOption) (net.Listener, error
9292

9393
for _, op := range opts {
9494
if err := op(path); err != nil {
95-
l.Close()
95+
_ = l.Close()
9696
return nil, err
9797
}
9898
}

sockets/unix_socket_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ func runTest(t *testing.T, path string, l net.Listener, echoStr string) {
1515
if err != nil {
1616
return
1717
}
18-
conn.Write([]byte(echoStr))
19-
conn.Close()
18+
_, _ = conn.Write([]byte(echoStr))
19+
_ = conn.Close()
2020
}
2121
}()
2222

0 commit comments

Comments
 (0)