Skip to content

Commit

Permalink
fix some linting issues (errCheck, misspell, unconvert)
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Jul 21, 2021
1 parent 790233e commit 4aafbac
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 45 deletions.
10 changes: 5 additions & 5 deletions nat/nat.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,17 @@ type PortMapping struct {
func splitParts(rawport string) (string, string, string) {
parts := strings.Split(rawport, ":")
n := len(parts)
containerport := parts[n-1]
containerPort := parts[n-1]

switch n {
case 1:
return "", "", containerport
return "", "", containerPort
case 2:
return "", parts[0], containerport
return "", parts[0], containerPort
case 3:
return parts[0], parts[1], containerport
return parts[0], parts[1], containerPort
default:
return strings.Join(parts[:n-2], ":"), parts[n-2], containerport
return strings.Join(parts[:n-2], ":"), parts[n-2], containerPort
}
}

Expand Down
2 changes: 1 addition & 1 deletion nat/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type portMapSorter []portMapEntry
func (s portMapSorter) Len() int { return len(s) }
func (s portMapSorter) Swap(i, j int) { s[i], s[j] = s[j], s[i] }

// sort the port so that the order is:
// Less sorts the port so that the order is:
// 1. port with larger specified bindings
// 2. larger port
// 3. port with tcp protocol
Expand Down
12 changes: 6 additions & 6 deletions nat/sort_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ func TestSortPortMap(t *testing.T) {

SortPortMap(ports, portMap)
if !reflect.DeepEqual(ports, []Port{
Port("9999/tcp"),
Port("6379/tcp"),
Port("8443/tcp"),
Port("8000/tcp"),
Port("22/tcp"),
Port("22/udp"),
"9999/tcp",
"6379/tcp",
"8443/tcp",
"8000/tcp",
"22/tcp",
"22/udp",
}) {
t.Errorf("failed to prioritize port with explicit mappings, got %v", ports)
}
Expand Down
12 changes: 6 additions & 6 deletions proxy/network_proxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (server *TCPEchoServer) Run() {
}

func (server *TCPEchoServer) LocalAddr() net.Addr { return server.listener.Addr() }
func (server *TCPEchoServer) Close() { server.listener.Close() }
func (server *TCPEchoServer) Close() { _ = server.listener.Close() }

func (server *UDPEchoServer) Run() {
go func() {
Expand All @@ -87,7 +87,7 @@ func (server *UDPEchoServer) Run() {
}

func (server *UDPEchoServer) LocalAddr() net.Addr { return server.conn.LocalAddr() }
func (server *UDPEchoServer) Close() { server.conn.Close() }
func (server *UDPEchoServer) Close() { _ = server.conn.Close() }

func testProxyAt(t *testing.T, proto string, proxy Proxy, addr string) {
defer proxy.Close()
Expand All @@ -97,7 +97,7 @@ func testProxyAt(t *testing.T, proto string, proxy Proxy, addr string) {
t.Fatalf("Can't connect to the proxy: %v", err)
}
defer client.Close()
client.SetDeadline(time.Now().Add(10 * time.Second))
_ = client.SetDeadline(time.Now().Add(10 * time.Second))
if _, err = client.Write(testBuf); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -197,12 +197,12 @@ func TestUDPWriteError(t *testing.T) {
}
defer client.Close()
// Make sure the proxy doesn't stop when there is no actual backend:
client.Write(testBuf)
client.Write(testBuf)
_, _ = client.Write(testBuf)
_, _ = client.Write(testBuf)
backend := NewEchoServer(t, "udp", "127.0.0.1:25587")
defer backend.Close()
backend.Run()
client.SetDeadline(time.Now().Add(10 * time.Second))
_ = client.SetDeadline(time.Now().Add(10 * time.Second))
if _, err = client.Write(testBuf); err != nil {
t.Fatal(err)
}
Expand Down
16 changes: 8 additions & 8 deletions proxy/tcp_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
backend, err := net.DialTCP("tcp", nil, proxy.backendAddr)
if err != nil {
proxy.Logger.Printf("Can't forward traffic to backend tcp/%v: %s\n", proxy.backendAddr, err)
client.Close()
_ = client.Close()
return
}

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

Expand All @@ -69,16 +69,16 @@ func (proxy *TCPProxy) clientLoop(client *net.TCPConn, quit chan bool) {
transferred += written
case <-quit:
// Interrupt the two brokers and "join" them.
client.Close()
backend.Close()
_ = client.Close()
_ = backend.Close()
for ; i < 2; i++ {
transferred += <-event
}
return
}
}
client.Close()
backend.Close()
_ = client.Close()
_ = backend.Close()
}

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

// Close stops forwarding the traffic.
func (proxy *TCPProxy) Close() { proxy.listener.Close() }
func (proxy *TCPProxy) Close() { _ = proxy.listener.Close() }

// FrontendAddr returns the TCP address on which the proxy is listening.
func (proxy *TCPProxy) FrontendAddr() net.Addr { return proxy.frontendAddr }
Expand Down
8 changes: 4 additions & 4 deletions proxy/udp_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ func (proxy *UDPProxy) replyLoop(proxyConn *net.UDPConn, clientAddr *net.UDPAddr
proxy.connTrackLock.Lock()
delete(proxy.connTrackTable, *clientKey)
proxy.connTrackLock.Unlock()
proxyConn.Close()
_ = proxyConn.Close()
}()

readBuf := make([]byte, UDPBufSize)
for {
proxyConn.SetReadDeadline(time.Now().Add(UDPConnTrackTimeout))
_ = proxyConn.SetReadDeadline(time.Now().Add(UDPConnTrackTimeout))
again:
read, err := proxyConn.Read(readBuf)
if err != nil {
Expand Down Expand Up @@ -151,11 +151,11 @@ func (proxy *UDPProxy) Run() {

// Close stops forwarding the traffic.
func (proxy *UDPProxy) Close() {
proxy.listener.Close()
_ = proxy.listener.Close()
proxy.connTrackLock.Lock()
defer proxy.connTrackLock.Unlock()
for _, conn := range proxy.connTrackTable {
conn.Close()
_ = conn.Close()
}
}

Expand Down
6 changes: 3 additions & 3 deletions sockets/inmem_socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func TestInmemSocket(t *testing.T) {
if err != nil {
return
}
conn.Write([]byte("hello"))
conn.Close()
_, _ = conn.Write([]byte("hello"))
_ = conn.Close()
}
}()

Expand All @@ -31,7 +31,7 @@ func TestInmemSocket(t *testing.T) {
t.Fatalf("expected `hello`, got %s", string(buf))
}

l.Close()
_ = l.Close()
conn, err = l.Dial("test", "test")
if err != errClosed {
t.Fatalf("expected `errClosed` error, got %v", err)
Expand Down
2 changes: 1 addition & 1 deletion sockets/unix_socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func NewUnixSocketWithOpts(path string, opts ...SockOption) (net.Listener, error

for _, op := range opts {
if err := op(path); err != nil {
l.Close()
_ = l.Close()
return nil, err
}
}
Expand Down
4 changes: 2 additions & 2 deletions sockets/unix_socket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func runTest(t *testing.T, path string, l net.Listener, echoStr string) {
if err != nil {
return
}
conn.Write([]byte(echoStr))
conn.Close()
_, _ = conn.Write([]byte(echoStr))
_ = conn.Close()
}
}()

Expand Down
16 changes: 8 additions & 8 deletions tlsconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,33 @@ var DefaultServerAcceptedCiphers = append(clientCipherSuites, acceptedCBCCiphers

// ServerDefault returns a secure-enough TLS configuration for the server TLS configuration.
func ServerDefault(ops ...func(*tls.Config)) *tls.Config {
tlsconfig := &tls.Config{
tlsConfig := &tls.Config{
// Avoid fallback by default to SSL protocols < TLS1.2
MinVersion: tls.VersionTLS12,
PreferServerCipherSuites: true,
CipherSuites: DefaultServerAcceptedCiphers,
}

for _, op := range ops {
op(tlsconfig)
op(tlsConfig)
}

return tlsconfig
return tlsConfig
}

// ClientDefault returns a secure-enough TLS configuration for the client TLS configuration.
func ClientDefault(ops ...func(*tls.Config)) *tls.Config {
tlsconfig := &tls.Config{
tlsConfig := &tls.Config{
// Prefer TLS1.2 as the client minimum
MinVersion: tls.VersionTLS12,
CipherSuites: clientCipherSuites,
}

for _, op := range ops {
op(tlsconfig)
op(tlsConfig)
}

return tlsconfig
return tlsConfig
}

// certPool returns an X.509 certificate pool from `caFile`, the certificate file.
Expand All @@ -99,11 +99,11 @@ func certPool(caFile string, exclusivePool bool) (*x509.CertPool, error) {
return nil, fmt.Errorf("failed to read system certificates: %v", err)
}
}
pem, err := ioutil.ReadFile(caFile)
pemData, err := ioutil.ReadFile(caFile)
if err != nil {
return nil, fmt.Errorf("could not read CA certificate %q: %v", caFile, err)
}
if !certPool.AppendCertsFromPEM(pem) {
if !certPool.AppendCertsFromPEM(pemData) {
return nil, fmt.Errorf("failed to append certificates from PEM file: %q", caFile)
}
return certPool, nil
Expand Down
2 changes: 1 addition & 1 deletion tlsconfig/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func TestConfigClientTLSClientCertOrKeyInvalid(t *testing.T) {
t.Fatal("Unable to create temporary empty file")
}
defer os.Remove(tempFile.Name())
tempFile.Close()
_ = tempFile.Close()

for i := 0; i < 2; i++ {
for _, invalid := range []string{"not-a-file", "", tempFile.Name()} {
Expand Down

0 comments on commit 4aafbac

Please sign in to comment.