Skip to content

Commit 359981c

Browse files
authored
Update golangci lint and clean up code (gatewayd-io#586)
* Update golangci-lint in CI * Remove deprecated linters * Disable fatcontext * Remove copied function, because CGO is no longer used in the SDK
1 parent 6951811 commit 359981c

File tree

5 files changed

+6
-61
lines changed

5 files changed

+6
-61
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
- name: Lint code with golangci-lint 🚨
7070
uses: golangci/golangci-lint-action@v4
7171
with:
72-
version: "v1.57"
72+
version: "v1.59.1"
7373
skip-pkg-cache: true
7474
install-mode: "goinstall"
7575

.golangci.yaml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,16 @@ linters:
1111
- nlreturn
1212
- testpackage
1313
- paralleltest
14-
- exhaustivestruct
1514
- exhaustruct
1615
- gocognit
1716
- gochecknoinits
1817
- gocyclo
19-
- maligned
2018
- funlen
2119
- maintidx
2220
- musttag
23-
- nosnakecase
24-
- goerr113
25-
- ifshort
26-
- deadcode
27-
- interfacer
28-
- scopelint
29-
- structcheck
30-
- varcheck
31-
- golint
21+
- err113
3222
- testifylint
23+
- fatcontext
3324
linters-settings:
3425
depguard:
3526
rules:

network/proxy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"time"
1111

1212
sdkAct "github.com/gatewayd-io/gatewayd-plugin-sdk/act"
13+
"github.com/gatewayd-io/gatewayd-plugin-sdk/databases/postgres"
1314
v1 "github.com/gatewayd-io/gatewayd-plugin-sdk/plugin/v1"
1415
"github.com/gatewayd-io/gatewayd/act"
1516
"github.com/gatewayd-io/gatewayd/config"
@@ -315,7 +316,7 @@ func (pr *Proxy) PassThroughToServer(conn *ConnWrapper, stack *Stack) *gerr.Gate
315316

316317
// Check if the client sent a SSL request and the server supports SSL.
317318
//nolint:nestif
318-
if conn.IsTLSEnabled() && IsPostgresSSLRequest(request) {
319+
if conn.IsTLSEnabled() && postgres.IsPostgresSSLRequest(request) {
319320
// Perform TLS handshake.
320321
if err := conn.UpgradeToTLS(func(net.Conn) {
321322
// Acknowledge the SSL request:
@@ -361,7 +362,7 @@ func (pr *Proxy) PassThroughToServer(conn *ConnWrapper, stack *Stack) *gerr.Gate
361362
// This return causes the client to start sending
362363
// StartupMessage over the TLS connection.
363364
return nil
364-
} else if !conn.IsTLSEnabled() && IsPostgresSSLRequest(request) {
365+
} else if !conn.IsTLSEnabled() && postgres.IsPostgresSSLRequest(request) {
365366
// Client sent a SSL request, but the server does not support SSL.
366367

367368
pr.Logger.Warn().Fields(

network/utils.go

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package network
22

33
import (
44
"crypto/sha256"
5-
"encoding/binary"
65
"encoding/hex"
76
"fmt"
87
"net"
@@ -122,23 +121,3 @@ func RemoteAddr(conn net.Conn) string {
122121
}
123122
return ""
124123
}
125-
126-
// IsPostgresSSLRequest returns true if the message is a SSL request.
127-
// This is copied from gatewayd-plugin-sdk to avoid the dependency on CGO.
128-
//
129-
//nolint:gomnd
130-
func IsPostgresSSLRequest(data []byte) bool {
131-
if len(data) < 8 {
132-
return false
133-
}
134-
135-
if binary.BigEndian.Uint32(data[0:4]) != 8 {
136-
return false
137-
}
138-
139-
if binary.BigEndian.Uint32(data[4:8]) != 80877103 {
140-
return false
141-
}
142-
143-
return true
144-
}

network/utils_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,6 @@ func TestResolve(t *testing.T) {
4545
assert.Equal(t, "127.0.0.1:53", address)
4646
}
4747

48-
// TestIsPostgresSSLRequest tests the IsPostgresSSLRequest function.
49-
// It checks the entire SSL request including the length.
50-
func TestIsPostgresSSLRequest(t *testing.T) {
51-
// Test a valid SSL request.
52-
sslRequest := []byte{0x00, 0x00, 0x00, 0x8, 0x04, 0xd2, 0x16, 0x2f}
53-
assert.True(t, IsPostgresSSLRequest(sslRequest))
54-
55-
// Test an invalid SSL request.
56-
invalidSSLRequest := []byte{0x00, 0x00, 0x00, 0x9, 0x04, 0xd2, 0x16, 0x2e}
57-
assert.False(t, IsPostgresSSLRequest(invalidSSLRequest))
58-
59-
// Test an invalid SSL request.
60-
invalidSSLRequest = []byte{0x04, 0xd2, 0x16}
61-
assert.False(t, IsPostgresSSLRequest(invalidSSLRequest))
62-
63-
// Test an invalid SSL request.
64-
invalidSSLRequest = []byte{0x00, 0x00, 0x00, 0x00, 0x04, 0xd2, 0x16, 0x2f, 0x00}
65-
assert.False(t, IsPostgresSSLRequest(invalidSSLRequest))
66-
}
67-
6848
var seedValues = []int{1000, 10000, 100000, 1000000, 10000000}
6949

7050
func BenchmarkGetID(b *testing.B) {
@@ -192,9 +172,3 @@ func BenchmarkExtractFieldValue(b *testing.B) {
192172
)
193173
}
194174
}
195-
196-
func BenchmarkIsPostgresSSLRequest(b *testing.B) {
197-
for i := 0; i < b.N; i++ {
198-
IsPostgresSSLRequest([]byte{0x00, 0x00, 0x00, 0x8, 0x04, 0xd2, 0x16, 0x2f})
199-
}
200-
}

0 commit comments

Comments
 (0)