diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 898a165..99db15b 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -11,25 +11,25 @@ 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 # TODO: matrix - - name: build + - name: Build run: go build -v ./... 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 # TODO: matrix - name: Test run: go test -v -race ./... @@ -37,7 +37,15 @@ 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 + uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # v8.0.0 + with: + version: v2.5.0 + + - name: Run linter + uses: magefile/mage-action@6f50bbb8ea47d56e62dee92392788acbc8192d0b # v3.1.0 + with: + version: latest + args: lint diff --git a/.golangci.yml b/.golangci.yml index c708124..a707b53 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/.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/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. 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/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...) +} 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")