From 838d1cbe0e5087adf8028ecc7efb35e5371d9464 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Wed, 13 Aug 2025 00:22:48 +0200 Subject: [PATCH 1/5] Update CI actions --- .github/workflows/go.yml | 14 +++++++------- README.md | 3 ++- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 898a165..b3de7da 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -11,12 +11,12 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 with: - go-version: 1.17 + go-version: 1.24 - name: build run: go build -v ./... @@ -24,12 +24,12 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: Set up Go - uses: actions/setup-go@v2 + uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 with: - go-version: 1.17 + go-version: 1.24 - name: Test run: go test -v -race ./... @@ -37,7 +37,7 @@ jobs: check: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: golangci-lint run: docker run -v $GITHUB_WORKSPACE:/repo -w /repo golangci/golangci-lint:v1.42 golangci-lint run diff --git a/README.md b/README.md index 99181b0..caa2413 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ -[![GoDoc](https://godoc.org/github.com/ngrok/sqlmw?status.svg)](https://godoc.org/github.com/ngrok/sqlmw) +[![docs](https://pkg.go.dev/badge/github.com/ngrok/sqlmw?status.svg)](https://pkg.go.dev/github.com/ngrok/sqlmw) # sqlmw + sqlmw provides an absurdly simple API that allows a caller to wrap a `database/sql` driver with middleware. From 42cb688d0e0a57f8b86fcb95e86e0d06f3eac7ab Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Thu, 23 Oct 2025 01:55:16 +0200 Subject: [PATCH 2/5] Upgrade `golangci-lint` configuration and fix some linter issues --- .golangci.yml | 10 +++++++--- conn.go | 4 ++-- conn_test.go | 4 ++-- stmt.go | 4 ++-- stmt_test.go | 4 ++-- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index c708124..84981ff 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,3 +1,7 @@ -issues: - exclude: - - "SA1019: .* has been deprecated since Go 1.*: Drivers should implement .*" +version: 2 +linters: + exclusions: + rules: + - linters: + - staticcheck + text: "SA1019: .* has been deprecated since Go 1.*: Drivers should implement .*" # TODO: upgrade Go version, and drop these functions? diff --git a/conn.go b/conn.go index be89a4a..46d13c8 100755 --- a/conn.go +++ b/conn.go @@ -129,7 +129,7 @@ func (c wrappedParentConn) BeginTx(ctx context.Context, opts driver.TxOptions) ( case <-ctx.Done(): return nil, ctx.Err() default: - return c.Conn.Begin() + return c.Begin() } } @@ -142,7 +142,7 @@ func (c wrappedParentConn) PrepareContext(ctx context.Context, query string) (dr case <-ctx.Done(): return nil, ctx.Err() default: - return c.Conn.Prepare(query) + return c.Prepare(query) } } diff --git a/conn_test.go b/conn_test.go index f1eb465..147cf19 100644 --- a/conn_test.go +++ b/conn_test.go @@ -124,7 +124,7 @@ func TestConnQueryContext_PassWrappedRowContext(t *testing.T) { } rows.Next() - rows.Close() + _ = rows.Close() if !ti.RowsCloseValid { t.Error("RowsClose context not valid") @@ -169,7 +169,7 @@ func TestConnPrepareContext_PassWrappedStmtContext(t *testing.T) { t.Fatalf("Prepare failed: %s", err) } - stmt.Close() + _ = stmt.Close() if !ti.StmtCloseValid { t.Error("StmtClose context not valid") diff --git a/stmt.go b/stmt.go index f8c89ba..f2d7e2f 100755 --- a/stmt.go +++ b/stmt.go @@ -89,7 +89,7 @@ func (s wrappedParentStmt) QueryContext(ctx context.Context, args []driver.Named case <-ctx.Done(): return nil, ctx.Err() } - return s.Stmt.Query(dargs) + return s.Query(dargs) } func (s wrappedParentStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (res driver.Result, err error) { @@ -106,5 +106,5 @@ func (s wrappedParentStmt) ExecContext(ctx context.Context, args []driver.NamedV case <-ctx.Done(): return nil, ctx.Err() } - return s.Stmt.Exec(dargs) + return s.Exec(dargs) } diff --git a/stmt_test.go b/stmt_test.go index 243f667..9d60083 100644 --- a/stmt_test.go +++ b/stmt_test.go @@ -89,8 +89,8 @@ func TestStmtQueryContext_PassWrappedRowContext(t *testing.T) { } rows.Next() - rows.Close() - stmt.Close() + _ = rows.Close() + _ = stmt.Close() if !ti.RowsNextValid { t.Error("RowsNext context not valid") From afd11020b538e4692f8501771aa13f2b00d9e36e Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Thu, 23 Oct 2025 01:56:04 +0200 Subject: [PATCH 3/5] Add foundation for `mage` We're using `mage` as our generic build / task tool --- .tools/go.mod | 7 +++++++ .tools/go.sum | 2 ++ go.mod | 2 ++ go.sum | 2 ++ magefiles/mage.go | 16 ++++++++++++++++ 5 files changed, 29 insertions(+) create mode 100644 .tools/go.mod create mode 100644 .tools/go.sum create mode 100644 go.sum create mode 100644 magefiles/mage.go diff --git a/.tools/go.mod b/.tools/go.mod new file mode 100644 index 0000000..156cd0d --- /dev/null +++ b/.tools/go.mod @@ -0,0 +1,7 @@ +module tools + +go 1.24.0 + +tool github.com/magefile/mage + +require github.com/magefile/mage v1.15.0 // indirect diff --git a/.tools/go.sum b/.tools/go.sum new file mode 100644 index 0000000..4ee1b87 --- /dev/null +++ b/.tools/go.sum @@ -0,0 +1,2 @@ +github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= +github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= diff --git a/go.mod b/go.mod index 07223b2..02aa3f8 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/ngrok/sqlmw go 1.13 + +require github.com/magefile/mage v1.15.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..4ee1b87 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= +github.com/magefile/mage v1.15.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= diff --git a/magefiles/mage.go b/magefiles/mage.go new file mode 100644 index 0000000..091bb68 --- /dev/null +++ b/magefiles/mage.go @@ -0,0 +1,16 @@ +//go:build mage + +package main + +import ( + "context" + + "github.com/magefile/mage/sh" +) + +// Lint runs the linter +func Lint(ctx context.Context) error { + //args := []string{"tool", "-modfile=./.tools/go.mod", "github.com/golangci/golangci-lint/v2/cmd/golangci-lint", "run", "--config", ".golangci.yml"} + args := []string{"run", "--config", ".golangci.yml"} + return sh.RunV("golangci-lint", args...) +} From 9f9082b797e0e0eee0e0d7854584b6cd7f263503 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Thu, 23 Oct 2025 11:40:48 +0200 Subject: [PATCH 4/5] Use `mage` in GitHub action for linting --- .github/workflows/go.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b3de7da..0137853 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -40,4 +40,12 @@ jobs: - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 - name: golangci-lint - run: docker run -v $GITHUB_WORKSPACE:/repo -w /repo golangci/golangci-lint:v1.42 golangci-lint run + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 + with: + version: v2.5.0 + + - name: Run Mage + uses: magefile/mage-action@6f50bbb8ea47d56e62dee92392788acbc8192d0b # v3.1.0 + with: + version: latest + args: lint From e9e200000c667c8fb8fad7a048b6d5e57d999221 Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Thu, 23 Oct 2025 11:43:04 +0200 Subject: [PATCH 5/5] Fix `golangci-lint` configuration version to be string --- .github/workflows/go.yml | 8 ++++---- .golangci.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 0137853..99db15b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -16,9 +16,9 @@ jobs: - name: Set up Go uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 with: - go-version: 1.24 + go-version: 1.24 # TODO: matrix - - name: build + - name: Build run: go build -v ./... test: @@ -29,7 +29,7 @@ jobs: - name: Set up Go uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # v5.5.0 with: - go-version: 1.24 + go-version: 1.24 # TODO: matrix - name: Test run: go test -v -race ./... @@ -44,7 +44,7 @@ jobs: with: version: v2.5.0 - - name: Run Mage + - name: Run linter uses: magefile/mage-action@6f50bbb8ea47d56e62dee92392788acbc8192d0b # v3.1.0 with: version: latest diff --git a/.golangci.yml b/.golangci.yml index 84981ff..a707b53 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,4 +1,4 @@ -version: 2 +version: "2" linters: exclusions: rules: