diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index dcc355a..16da9f5 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -29,10 +29,10 @@ jobs: with: fetch-depth: '0' - - name: Install Go 1.24 + - name: Install Go 1.25 uses: actions/setup-go@v6 with: - go-version: 1.24 + go-version: 1.25 - name: Cache Dependencies uses: actions/cache@v4 diff --git a/.golangci.yml b/.golangci.yml index ec8009b..7128429 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,51 +1,32 @@ -run: - deadline: 5m - tests: true - allow-parallel-runners: true - modules-download-mode: readonly - build-tags: [ all, integration ] +version: "2" -linters-settings: - revive: - rules: - - name: package-comments - disabled: true - goimports: - local-prefixes: github.com/scylladb/gocqlx - gofumpt: - extra-rules: true - govet: - enable-all: true - disable: - - shadow - errcheck: - check-blank: true - gocognit: - min-complexity: 50 - gocritic: - enabled-tags: - - diagnostic - - performance - - style - disabled-checks: - - commentedOutCode - - evalOrder - - hugeParam - - importShadow - - yodaStyleExpr - - whyNoLint - lll: - line-length: 180 +formatters: + enable: + - goimports + + settings: + goimports: + local-prefixes: + - github.com/scylladb/gocqlx + golines: + max-len: 120 + gofumpt: + extra-rules: true linters: - disable-all: true + exclusions: + rules: + - path: '(.+)_test\.go' + text: "fieldalignment" + linters: + - govet + + default: none enable: + - nolintlint - errcheck - gocritic - - gofumpt - goheader - - goimports - - gosimple - govet - ineffassign - lll @@ -55,26 +36,41 @@ linters: - staticcheck - thelper - tparallel - - typecheck - unused - forbidigo + settings: + revive: + rules: + - name: package-comments + disabled: true + govet: + enable-all: true + disable: + - shadow + errcheck: + check-blank: false + gocognit: + min-complexity: 50 + gocritic: + enabled-tags: + - diagnostic + - performance + - style + disabled-checks: + - commentedOutCode + - evalOrder + - hugeParam + - importShadow + - yodaStyleExpr + - whyNoLint + lll: + line-length: 180 + nolintlint: + allow-no-explanation: [ golines ] + require-explanation: true + require-specific: true -issues: - new: true - new-from-rev: origin/master - exclude-use-default: false - exclude: - - composite literal uses unkeyed fields - - Error return value of `.+\.Close` is not checked - - method Json should be JSON - exclude-rules: - - path: (.*_test.go|migrate/example|gocqlxtest/) - linters: - - fieldalignment - - govet - - errcheck - - path: doc_test.go - linters: - - unused - - revive - +run: + build-tags: + - integration + - all \ No newline at end of file diff --git a/Makefile b/Makefile index 2624536..2d76d60 100644 --- a/Makefile +++ b/Makefile @@ -24,8 +24,7 @@ export PATH := $(GOBIN):$(PATH) GOOS := $(shell uname | tr '[:upper:]' '[:lower:]') GOARCH := $(shell go env GOARCH) -GOLANGCI_VERSION := 1.64.8 -FIELDALIGNMENT_VERSION := 0.24.0 +GOLANGCI_VERSION := 2.5.0 ifeq ($(GOARCH),arm64) GOLANGCI_DOWNLOAD_URL := "https://github.com/golangci/golangci-lint/releases/download/v$(GOLANGCI_VERSION)/golangci-lint-$(GOLANGCI_VERSION)-$(GOOS)-arm64.tar.gz" @@ -97,7 +96,6 @@ get-deps: get-tools: @echo "==> Installing tools at $(GOBIN)..." @$(MAKE) install-golangci-lint - @$(MAKE) install-fieldalignment .require-golangci-lint: ifeq ($(shell if golangci-lint --version 2>/dev/null | grep ${GOLANGCI_VERSION} 1>/dev/null 2>&1; then echo "ok"; else echo "need-install"; fi), need-install) @@ -108,15 +106,6 @@ install-golangci-lint: @echo "==> Installing golangci-lint ${GOLANGCI_VERSION} at $(GOBIN)..." $(call dl_tgz,golangci-lint,$(GOLANGCI_DOWNLOAD_URL)) -.require-fieldalignment: -ifeq ($(shell if fieldalignment -V=full 1>/dev/null 2>&1; then echo "ok"; else echo "need-install"; fi), need-install) - $(MAKE) install-golangci-lint -endif - -install-fieldalignment: - @echo "==> Installing fieldalignment ${FIELDALIGNMENT_VERSION} at $(GOBIN)..." - @go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@v${FIELDALIGNMENT_VERSION} - define dl_tgz @mkdir "$(GOBIN)" 2>/dev/null || true @echo "Downloading $(GOBIN)/$(1)"; diff --git a/README.md b/README.md index 92c01db..d4aa91d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ If you are using GocqlX v3.0.0 or newer, you must ensure your `go.mod` includes ```go // Use the latest version of scylladb/gocql; check for updates at https://github.com/scylladb/gocql/releases -replace github.com/gocql/gocql => github.com/scylladb/gocql v1.15.3 +replace github.com/gocql/gocql => github.com/scylladb/gocql v1.16.0 ``` This is required because GocqlX relies on ScyllaDB-specific extensions and bug fixes introduced in the gocql fork. Attempting to use the standard gocql driver with GocqlX v3.0.0+ may lead to build or runtime issues. diff --git a/benchmark_test.go b/benchmark_test.go index 6777a81..66ace8c 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -162,12 +162,13 @@ func BenchmarkBaseGocqlSelect(b *testing.B) { v := make([]*benchPerson, 100) p := new(benchPerson) for iter.Scan(&p.ID, &p.FirstName, &p.LastName, &p.Email, &p.Gender, &p.IPAddress) { - v = append(v, p) // nolint:staticcheck + v = append(v, p) p = new(benchPerson) } if err := iter.Close(); err != nil { b.Fatal(err) } + _ = v } } diff --git a/cmd/schemagen/camelize.go b/cmd/schemagen/camelize.go index f6683e1..b9161e8 100644 --- a/cmd/schemagen/camelize.go +++ b/cmd/schemagen/camelize.go @@ -16,7 +16,7 @@ func camelize(s string) string { l := len(buf) for i := 0; i < l; i++ { - if !(allowedBindRune(buf[i]) || buf[i] == '_') { + if !allowedBindRune(buf[i]) && buf[i] != '_' { panic(fmt.Sprint("not allowed name ", s)) } diff --git a/cmd/schemagen/testdata/go.mod b/cmd/schemagen/testdata/go.mod index 8a13592..21e92df 100644 --- a/cmd/schemagen/testdata/go.mod +++ b/cmd/schemagen/testdata/go.mod @@ -1,8 +1,6 @@ module schemagentest -go 1.24.0 - -toolchain go1.24.5 +go 1.25.0 require ( github.com/gocql/gocql v1.7.0 @@ -12,12 +10,12 @@ require ( require ( github.com/google/uuid v1.6.0 // indirect - github.com/klauspost/compress v1.18.0 // indirect + github.com/klauspost/compress v1.18.1 // indirect github.com/scylladb/go-reflectx v1.0.1 // indirect gopkg.in/inf.v0 v0.9.1 // indirect ) replace ( - github.com/gocql/gocql => github.com/scylladb/gocql v1.15.3 + github.com/gocql/gocql => github.com/scylladb/gocql v1.16.1 github.com/scylladb/gocqlx/v3 => ../../.. ) diff --git a/cmd/schemagen/testdata/go.sum b/cmd/schemagen/testdata/go.sum index 73ac7ea..cbec210 100644 --- a/cmd/schemagen/testdata/go.sum +++ b/cmd/schemagen/testdata/go.sum @@ -1,52 +1,28 @@ -github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= -github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= -github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= -github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co= +github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/scylladb/go-reflectx v1.0.1 h1:b917wZM7189pZdlND9PbIJ6NQxfDPfBvUaQ7cjj1iZQ= github.com/scylladb/go-reflectx v1.0.1/go.mod h1:rWnOfDIRWBGN0miMLIcoPt/Dhi2doCMZqwMCJ3KupFc= -github.com/scylladb/gocql v1.15.3 h1:0vJT5pm7g5v8/pCs3tuXuRAfSRWvc1kib8J846Z+Z4g= -github.com/scylladb/gocql v1.15.3/go.mod h1:+rInt+HjERaMEYC4N8LocQQEAdREhYKU4QPkE00K5dA= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/net v0.0.0-20220526153639-5463443f8c37 h1:lUkvobShwKsOesNfWWlCS5q7fnbG1MEliIzwu886fn8= -golang.org/x/net v0.0.0-20220526153639-5463443f8c37/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +github.com/scylladb/gocql v1.16.1 h1:mxqUoOoHPrhzBNN+S0X195N+wCPZ5nrstfFz4QtBaZs= +github.com/scylladb/gocql v1.16.1/go.mod h1:MSg2nr90XMcU0doVnISX3OtarTac5tSCGk6Q6QJd6oQ= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= +go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= +golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= +golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs= +sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4= diff --git a/doc_test.go b/doc_test.go index 11c20e1..b2dcbf9 100644 --- a/doc_test.go +++ b/doc_test.go @@ -29,6 +29,8 @@ func ExampleUDT() { FirstName string LastName string } + + _ = FullName{} } func ExampleUDT_wraper() { @@ -42,4 +44,6 @@ func ExampleUDT_wraper() { gocqlx.UDT *FullName } + + _ = FullNameUDT{} } diff --git a/example_test.go b/example_test.go index 557a2f2..653d27d 100644 --- a/example_test.go +++ b/example_test.go @@ -35,7 +35,7 @@ func TestExample(t *testing.T) { } defer session.Close() - session.ExecStmt(`DROP KEYSPACE examples`) + _ = session.ExecStmt(`DROP KEYSPACE examples`) basicCreateAndPopulateKeyspace(t, session, "examples") createAndPopulateKeyspaceAllTypes(t, session) @@ -270,7 +270,7 @@ func createAndPopulateKeyspaceAllTypes(t *testing.T, session gocqlx.Session) { copy(byteID[:], id) date := time.Date(2021, time.December, 11, 10, 23, 0, 0, time.UTC) - var double float64 = 1.2 // nolint:revive + var double float64 = 1.2 //nolint:staticcheck // type needs to be enforces var float float32 = 1.3 var integer int32 = 123 listInt := []int32{1, 2, 3} diff --git a/go.mod b/go.mod index 3c7d9b8..ec80da0 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/scylladb/gocqlx/v3 -go 1.24.0 - -toolchain go1.24.5 +go 1.25.0 require ( github.com/gocql/gocql v1.7.0 @@ -15,7 +13,7 @@ require ( require ( github.com/google/uuid v1.6.0 // indirect - github.com/klauspost/compress v1.18.0 // indirect + github.com/klauspost/compress v1.18.1 // indirect ) -replace github.com/gocql/gocql => github.com/scylladb/gocql v1.15.3 +replace github.com/gocql/gocql => github.com/scylladb/gocql v1.16.1 diff --git a/go.sum b/go.sum index 38137a4..86a70dc 100644 --- a/go.sum +++ b/go.sum @@ -1,55 +1,41 @@ -github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932/go.mod h1:NOuUCSz6Q9T7+igc/hlvDOUdtWKryOrtFyIVABv/p7k= +github.com/bitly/go-hostpool v0.1.1 h1:SsovT4BFqgJQBAESkk2QgeeL7bqKq9oJie8JnD00R+Q= +github.com/bitly/go-hostpool v0.1.1/go.mod h1:iwXQOF7+y3cO8vituSqGpBYf02TYTzxK4S2c4rf4cJs= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc1Q53c0bnx2ufif5kANL7bfZWcc6VJWJd8= github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4= -github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= -github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/klauspost/compress v1.18.1 h1:bcSGx7UbpBqMChDtsF28Lw6v/G94LPrrbMbdC3JH2co= +github.com/klauspost/compress v1.18.1/go.mod h1:ZQFFVG+MdnR0P+l6wpXgIL4NTtwiKIdBnrBd8Nrxr+0= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/psanford/memfs v0.0.0-20241019191636-4ef911798f9b h1:xzjEJAHum+mV5Dd5KyohRlCyP03o4yq6vNpEUtAJQzI= github.com/psanford/memfs v0.0.0-20241019191636-4ef911798f9b/go.mod h1:tcaRap0jS3eifrEEllL6ZMd9dg8IlDpi2S1oARrQ+NI= github.com/scylladb/go-reflectx v1.0.1 h1:b917wZM7189pZdlND9PbIJ6NQxfDPfBvUaQ7cjj1iZQ= github.com/scylladb/go-reflectx v1.0.1/go.mod h1:rWnOfDIRWBGN0miMLIcoPt/Dhi2doCMZqwMCJ3KupFc= -github.com/scylladb/gocql v1.15.3 h1:0vJT5pm7g5v8/pCs3tuXuRAfSRWvc1kib8J846Z+Z4g= -github.com/scylladb/gocql v1.15.3/go.mod h1:+rInt+HjERaMEYC4N8LocQQEAdREhYKU4QPkE00K5dA= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/net v0.0.0-20220526153639-5463443f8c37 h1:lUkvobShwKsOesNfWWlCS5q7fnbG1MEliIzwu886fn8= -golang.org/x/net v0.0.0-20220526153639-5463443f8c37/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +github.com/scylladb/gocql v1.16.1 h1:mxqUoOoHPrhzBNN+S0X195N+wCPZ5nrstfFz4QtBaZs= +github.com/scylladb/gocql v1.16.1/go.mod h1:MSg2nr90XMcU0doVnISX3OtarTac5tSCGk6Q6QJd6oQ= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= +go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= +golang.org/x/net v0.46.0 h1:giFlY12I07fugqwPuWJi68oOnpfqFnJIJzaIIm2JVV4= +golang.org/x/net v0.46.0/go.mod h1:Q9BGdFy1y4nkUwiLvT5qtyhAnEHgnQ/zd8PfU6nc210= golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= -sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= +sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs= +sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4= diff --git a/gocqlx.go b/gocqlx.go index edcc06a..b1fa542 100644 --- a/gocqlx.go +++ b/gocqlx.go @@ -20,15 +20,15 @@ func structOnlyError(t reflect.Type) error { return fmt.Errorf("expected a struct but got %s", t.Kind()) } - if isUnmarshaller := reflect.PtrTo(t).Implements(unmarshallerInterface); isUnmarshaller { + if isUnmarshaller := reflect.PointerTo(t).Implements(unmarshallerInterface); isUnmarshaller { return fmt.Errorf("expected a struct but the provided struct type %s implements gocql.Unmarshaler", t.Name()) } - if isUDTUnmarshaller := reflect.PtrTo(t).Implements(udtUnmarshallerInterface); isUDTUnmarshaller { + if isUDTUnmarshaller := reflect.PointerTo(t).Implements(udtUnmarshallerInterface); isUDTUnmarshaller { return fmt.Errorf("expected a struct but the provided struct type %s implements gocql.UDTUnmarshaler", t.Name()) } - if isAutoUDT := reflect.PtrTo(t).Implements(autoUDTInterface); isAutoUDT { + if isAutoUDT := reflect.PointerTo(t).Implements(autoUDTInterface); isAutoUDT { return fmt.Errorf("expected a struct but the provided struct type %s implements gocqlx.UDT", t.Name()) } diff --git a/iterx.go b/iterx.go index 8d4b093..90d295f 100644 --- a/iterx.go +++ b/iterx.go @@ -62,7 +62,7 @@ func (iter *Iterx) StructOnly() *Iterx { // If no rows were selected, ErrNotFound is returned. func (iter *Iterx) Get(dest interface{}) error { iter.scanAny(dest) - iter.Close() + _ = iter.Close() return iter.checkErrAndNotFound() } @@ -119,7 +119,7 @@ func (iter *Iterx) scanAny(dest interface{}) bool { // If no rows were selected, ErrNotFound is NOT returned. func (iter *Iterx) Select(dest interface{}) error { iter.scanAll(dest) - iter.Close() + _ = iter.Close() return iter.err } @@ -209,7 +209,7 @@ func (iter *Iterx) scanAll(dest interface{}) bool { // - it is not a struct // - it has no exported fields func (iter *Iterx) isScannable(t reflect.Type) bool { - ptr := reflect.PtrTo(t) + ptr := reflect.PointerTo(t) switch { case ptr.Implements(unmarshallerInterface): return true @@ -260,7 +260,7 @@ func (iter *Iterx) structScan(value reflect.Value) bool { } if iter.fields == nil { - columns := columnNames(iter.Iter.Columns()) + columns := columnNames(iter.Columns()) cas := len(columns) > 0 && columns[0] == appliedColumn iter.fields = iter.Mapper.TraversalsByName(value.Type(), columns) @@ -342,7 +342,7 @@ func (iter *Iterx) Close() error { func (iter *Iterx) checkErrAndNotFound() error { if iter.err != nil { return iter.err - } else if iter.Iter.NumRows() == 0 { + } else if iter.NumRows() == 0 { return gocql.ErrNotFound } return nil diff --git a/iterx_test.go b/iterx_test.go index f6fc339..795edb2 100644 --- a/iterx_test.go +++ b/iterx_test.go @@ -260,7 +260,7 @@ func TestIterxUDT(t *testing.T) { } t.Cleanup(func() { - session.Query(deleteStmt, nil).Bind(testuuid).ExecRelease() // nolint:errcheck + _ = session.Query(deleteStmt, nil).Bind(testuuid).ExecRelease() }) t.Run("insert-bind", func(t *testing.T) { @@ -930,7 +930,9 @@ func TestIterxPaging(t *testing.T) { AllowFiltering(). Columns("id", "val").ToCql() iter := session.Query(stmt, names).Bind(100).PageSize(10).Iter() - defer iter.Close() + defer func() { + _ = iter.Close() + }() var cnt int for { diff --git a/migrate/checksum.go b/migrate/checksum.go index f302f50..49fce10 100644 --- a/migrate/checksum.go +++ b/migrate/checksum.go @@ -23,7 +23,9 @@ func fileChecksum(f fs.FS, path string) (string, error) { if err != nil { return "", nil } - defer file.Close() + defer func() { + _ = file.Close() + }() h := md5.New() if _, err := io.Copy(h, file); err != nil { diff --git a/migrate/migrate.go b/migrate/migrate.go index d7ab21f..b1b8847 100644 --- a/migrate/migrate.go +++ b/migrate/migrate.go @@ -225,7 +225,7 @@ func applyMigration(ctx context.Context, session gocqlx.Session, f fs.FS, path s } b, err := io.ReadAll(file) - file.Close() + _ = file.Close() if err != nil { return err } diff --git a/migrate/migrate_test.go b/migrate/migrate_test.go index e0ed563..359dc48 100644 --- a/migrate/migrate_test.go +++ b/migrate/migrate_test.go @@ -56,7 +56,7 @@ func TestPending(t *testing.T) { defer recreateTables(t, session) f := memfs.New() - writeFile(f, 0, fmt.Sprintf(insertMigrate, 0)+";") + writeFile(t, f, 0, fmt.Sprintf(insertMigrate, 0)+";") pending, err := migrate.Pending(ctx, session, f) if err != nil { @@ -80,7 +80,7 @@ func TestPending(t *testing.T) { } for i := 1; i < 3; i++ { - writeFile(f, i, fmt.Sprintf(insertMigrate, i)+";") + writeFile(t, f, i, fmt.Sprintf(insertMigrate, i)+";") } pending, err = migrate.Pending(ctx, session, f) @@ -101,7 +101,7 @@ func TestMigration(t *testing.T) { ctx := context.Background() t.Run("init", func(t *testing.T) { - if err := migrate.FromFS(ctx, session, makeTestFS(2)); err != nil { + if err := migrate.FromFS(ctx, session, makeTestFS(t, 2)); err != nil { t.Fatal(err) } if c := countMigrations(t, session); c != 2 { @@ -110,7 +110,7 @@ func TestMigration(t *testing.T) { }) t.Run("update", func(t *testing.T) { - if err := migrate.FromFS(ctx, session, makeTestFS(4)); err != nil { + if err := migrate.FromFS(ctx, session, makeTestFS(t, 4)); err != nil { t.Fatal(err) } if c := countMigrations(t, session); c != 4 { @@ -119,7 +119,7 @@ func TestMigration(t *testing.T) { }) t.Run("ahead", func(t *testing.T) { - err := migrate.FromFS(ctx, session, makeTestFS(2)) + err := migrate.FromFS(ctx, session, makeTestFS(t, 2)) if err == nil || !strings.Contains(err.Error(), "ahead") { t.Fatal("expected error") } else { @@ -128,8 +128,8 @@ func TestMigration(t *testing.T) { }) t.Run("tempered with file", func(t *testing.T) { - f := makeTestFS(4) - writeFile(f, 3, "SELECT * FROM bla;") + f := makeTestFS(t, 4) + writeFile(t, f, 3, "SELECT * FROM bla;") if err := migrate.FromFS(ctx, session, f); err == nil || !strings.Contains(err.Error(), "tampered") { t.Fatal("expected error") @@ -148,8 +148,11 @@ func TestMigrationNoSemicolon(t *testing.T) { t.Fatal(err) } - f := makeTestFS(0) - f.WriteFile("0.cql", []byte(fmt.Sprintf(insertMigrate, 0)+";"+fmt.Sprintf(insertMigrate, 1)), fs.ModePerm) + f := makeTestFS(t, 0) + err := f.WriteFile("0.cql", []byte(fmt.Sprintf(insertMigrate, 0)+";"+fmt.Sprintf(insertMigrate, 1)), fs.ModePerm) + if err != nil { + t.Fatal(err) + } ctx := context.Background() if err := migrate.FromFS(ctx, session, f); err != nil { @@ -169,10 +172,13 @@ func TestMigrationWithTrailingComment(t *testing.T) { t.Fatal(err) } - f := makeTestFS(0) + f := makeTestFS(t, 0) // Create a migration with a trailing comment (this should reproduce the issue) migrationContent := fmt.Sprintf(insertMigrate, 0) + "; -- ttl 1 hour" - f.WriteFile("0.cql", []byte(migrationContent), fs.ModePerm) + err := f.WriteFile("0.cql", []byte(migrationContent), fs.ModePerm) + if err != nil { + t.Fatal(err) + } ctx := context.Background() if err := migrate.FromFS(ctx, session, f); err != nil { @@ -341,7 +347,7 @@ func TestMigrationCallback(t *testing.T) { ctx := context.Background() t.Run("init", func(t *testing.T) { - f := makeTestFS(2) + f := makeTestFS(t, 2) reset() if err := migrate.FromFS(ctx, session, f); err != nil { @@ -351,7 +357,7 @@ func TestMigrationCallback(t *testing.T) { }) t.Run("no duplicate calls", func(t *testing.T) { - f := makeTestFS(4) + f := makeTestFS(t, 4) reset() if err := migrate.FromFS(ctx, session, f); err != nil { @@ -361,9 +367,9 @@ func TestMigrationCallback(t *testing.T) { }) t.Run("in calls", func(t *testing.T) { - f := makeTestFS(4) - writeFile(f, 4, "\n-- CALL Foo;\n") - writeFile(f, 5, "\n-- CALL Bar;\n") + f := makeTestFS(t, 4) + writeFile(t, f, 4, "\n-- CALL Foo;\n") + writeFile(t, f, 5, "\n-- CALL Bar;\n") reset() if err := migrate.FromFS(ctx, session, f); err != nil { @@ -383,14 +389,19 @@ func countMigrations(tb testing.TB, session gocqlx.Session) int { return v } -func makeTestFS(n int) *memfs.FS { +func makeTestFS(tb testing.TB, n int) *memfs.FS { + tb.Helper() f := memfs.New() for i := 0; i < n; i++ { - writeFile(f, i, fmt.Sprintf(insertMigrate, i)+";") + writeFile(tb, f, i, fmt.Sprintf(insertMigrate, i)+";") } return f } -func writeFile(f *memfs.FS, i int, text string) { - f.WriteFile(fmt.Sprint(i, ".cql"), []byte(text), fs.ModePerm) +func writeFile(tb testing.TB, f *memfs.FS, i int, text string) { + tb.Helper() + err := f.WriteFile(fmt.Sprint(i, ".cql"), []byte(text), fs.ModePerm) + if err != nil { + tb.Fatal(err) + } } diff --git a/qb/select.go b/qb/select.go index e1b2141..b4680f4 100644 --- a/qb/select.go +++ b/qb/select.go @@ -132,7 +132,7 @@ func (b *SelectBuilder) From(table string) *SelectBuilder { } // Json sets the clause of the query. -func (b *SelectBuilder) Json() *SelectBuilder { // nolint: revive +func (b *SelectBuilder) Json() *SelectBuilder { b.json = true return b } diff --git a/queryx.go b/queryx.go index 2e7d37e..cc8efb3 100644 --- a/queryx.go +++ b/queryx.go @@ -181,7 +181,7 @@ func (q *Queryx) bindStructArgs(arg0 interface{}, arg1 map[string]interface{}) ( err := q.Mapper.TraversalsByNameFunc(v.Type(), q.Names, func(i int, t []int) error { if len(t) != 0 { - val := reflectx.FieldByIndexesReadOnly(v, t) // nolint:scopelint + val := reflectx.FieldByIndexesReadOnly(v, t) arglist = append(arglist, val.Interface()) } else { val, ok := arg1[q.Names[i]] diff --git a/queryx_bench_test.go b/queryx_bench_test.go index 422a3cd..863da48 100644 --- a/queryx_bench_test.go +++ b/queryx_bench_test.go @@ -16,7 +16,10 @@ func BenchmarkCompileNamedQuery(b *testing.B) { q := []byte("INSERT INTO cycling.cyclist_name (id, user_uuid, firstname, stars) VALUES (:id, :user_uuid, :firstname, :stars)") b.ResetTimer() for i := 0; i < b.N; i++ { - gocqlx.CompileNamedQuery(q) + _, _, err := gocqlx.CompileNamedQuery(q) + if err != nil { + b.Fatal(err) + } } } diff --git a/table/table.go b/table/table.go index b210852..3e3fa31 100644 --- a/table/table.go +++ b/table/table.go @@ -37,7 +37,7 @@ type Table struct { } // New creates new Table based on table schema read from Metadata. -func New(m Metadata) *Table { // nolint: gocritic +func New(m Metadata) *Table { t := &Table{ metadata: m, }