diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 2e103caf..d3a5cb8e 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -24,12 +24,12 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.23.6 + go-version: '1.27.1' - name: Lint Go Code run: | export PATH=$PATH:$(go env GOPATH)/bin - go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.8 + go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.2 make ci-lint @@ -45,10 +45,10 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.23.6 + go-version: '1.27.1' - - name: Run Unit tests - run: make test + - name: Run all tests + run: go test -count=1 ./... - name: Run coverage run: go test -coverprofile=coverage.txt -covermode=atomic $(go list ./... | grep -v /vendor/ | grep -v /api/ | grep -v /cmd/) @@ -73,7 +73,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.23.6 + go-version: '1.27.1' - name: Build run: make build && make build-sponge diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 37339c4d..42c0c44f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: 1.23.6 + go-version: '1.27.1' - name: Create release on GitHub uses: goreleaser/goreleaser-action@v3 diff --git a/.gitignore b/.gitignore index 4d2ac996..8ad6f8fc 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ # Dependency directories (remove the comment below to include it) vendor/ dist/ +pkg/sgorm/sqlite/*.db # idea .idea diff --git a/.golangci.yml b/.golangci.yml index 6baabeeb..49fb9415 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,276 +1,242 @@ -# See the file `https://github.com/golangci/golangci-lint/blob/master/.golangci.yml` to have a list of all available configuration options. - +version: "2" +run: + timeout: 5m + tests: false linters: - disable-all: true - # This list of linters is not a recommendation (same thing for all this configuration file). - # We intentionally use a limited set of linters. - # See the comment on top of this file. + default: none enable: - - revive - - goimports - - unused + - copyloopvar - dogsled - errcheck - goconst - gocyclo - - gosimple + - goprintffuncname - govet - lll - misspell + - revive + - staticcheck - unconvert + - unused - whitespace - - staticcheck - - goprintffuncname - - copyloopvar - - #- gofmt - #- stylecheck - #- bodyclose - #- intrange - #- gochecknoinits - #- gocritic - #- errorlint - #- dupl - #- depguard - #- ineffassign - #- gosec - #- unparam - #- funlen - #- gocheckcompilerdirectives - #- godox - #- mnd - #- nakedret - #- noctx - #- nolintlint - #- testifylint - - -linters-settings: - goimports: - local-prefixes: github.com/go-dev-frame/sponge - gofmt: - rewrite-rules: - - pattern: 'interface{}' - replacement: 'any' - depguard: - rules: - logger: - deny: - # logging is allowed only by logutils.Log, - #- pkg: "github.com/sirupsen/logrus" - # desc: logging is allowed only by logutils.Log. - - pkg: "github.com/pkg/errors" - desc: Should be replaced by standard lib errors package. - #- pkg: "github.com/instana/testify" - # desc: It's a fork of github.com/stretchr/testify. - files: - # logrus is allowed to use only in logutils package. - #- "!**/pkg/logutils/**.go" - dupl: - # tokens count to trigger issue, 150 by default - threshold: 100 - dogsled: - # checks assignments with too many blank identifiers; default is 2 - max-blank-identifiers: 2 - funlen: - lines: -1 # the number of lines (code + empty lines) is not a right metric and leads to code without empty line or one-liner. - statements: 50 - goconst: - min-len: 4 - min-occurrences: 4 - gocritic: - enabled-tags: - - diagnostic - - experimental - - opinionated - - performance - - style - disabled-checks: - - dupImport # https://github.com/go-critic/go-critic/issues/845 - - ifElseChain - - octalLiteral - - whyNoLint - gocyclo: - min-complexity: 20 - godox: - keywords: - - FIXME - mnd: - # don't include the "operation" and "assign" - checks: - - argument - - case - - condition - - return - ignored-numbers: - - '0' - - '1' - - '2' - - '3' - ignored-functions: - - strings.SplitN - govet: - settings: - printf: - funcs: - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf - - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf - enable: - - nilness - - shadow - errorlint: - asserts: false - lll: - line-length: 200 - misspell: - locale: US - ignore-words: - - "importas" # linter name - nolintlint: - allow-unused: false # report any unused nolint directives - require-explanation: true # require an explanation for nolint directives - require-specific: true # require nolint directives to be specific about which linter is being skipped - revive: + settings: + depguard: + rules: + logger: + deny: + - pkg: github.com/pkg/errors + desc: Should be replaced by standard lib errors package. + dogsled: + max-blank-identifiers: 2 + dupl: + threshold: 100 + errorlint: + asserts: false + funlen: + lines: -1 + statements: 50 + goconst: + min-len: 4 + min-occurrences: 4 + # Keep v1 behavior for calls and literal tables used by the generator. + exclude-types: + - Call + - CompositeLit + gocritic: + disabled-checks: + - dupImport + - ifElseChain + - octalLiteral + - whyNoLint + enabled-tags: + - diagnostic + - experimental + - opinionated + - performance + - style + gocyclo: + min-complexity: 20 + godox: + keywords: + - FIXME + govet: + enable: + - nilness + - shadow + settings: + printf: + funcs: + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf + - (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf + lll: + line-length: 200 + misspell: + locale: US + ignore-rules: + - importas + mnd: + checks: + - argument + - case + - condition + - return + ignored-numbers: + - "0" + - "1" + - "2" + - "3" + ignored-functions: + - strings.SplitN + nolintlint: + require-explanation: true + require-specific: true + allow-unused: false + revive: + rules: + - name: unexported-return + disabled: true + - name: indent-error-flow + - name: argument-limit + arguments: + - 8 + - name: atomic + - name: bare-return + - name: blank-imports + - name: bool-literal-in-expr + - name: call-to-gc + - name: confusing-naming + - name: confusing-results + - name: constant-logical-expr + - name: context-as-argument + - name: context-keys-type + - name: deep-exit + - name: defer + - name: dot-imports + - name: duplicated-imports + - name: early-return + - name: empty-block + - name: error-naming + - name: error-return + - name: error-strings + - name: errorf + - name: function-result-limit + arguments: + - 3 + - name: identical-branches + - name: if-return + - name: import-shadowing + - name: increment-decrement + - name: modifies-parameter + - name: modifies-value-receiver + - name: package-comments + - name: range + - name: range-val-address + - name: range-val-in-closure + - name: receiver-naming + - name: redefines-builtin-id + - name: string-of-int + - name: struct-tag + - name: superfluous-else + - name: time-naming + - name: unconditional-recursion + - name: unexported-naming + - name: unnecessary-stmt + - name: unreachable-code + - name: var-declaration + - name: var-naming + - name: waitgroup-by-value + staticcheck: + # Match the previous staticcheck and gosimple linters; omit new style and quick-fix checks. + checks: + - SA* + - S* + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling rules: - - name: unexported-return - disabled: true - #- name: unused-receiver - - name: indent-error-flow - #- name: unused-parameter - - name: argument-limit - arguments: [ 8 ] - - name: atomic - - name: bare-return - - name: blank-imports - - name: bool-literal-in-expr - - name: call-to-gc - - name: confusing-naming - - name: confusing-results - - name: constant-logical-expr - - name: context-as-argument - - name: context-keys-type - - name: deep-exit - - name: defer - - name: dot-imports - - name: duplicated-imports - - name: early-return - - name: empty-block - #- name: empty-lines - - name: error-naming - - name: error-return - - name: error-strings - - name: errorf - - name: function-result-limit - arguments: [ 3 ] - - name: identical-branches - - name: if-return - - name: import-shadowing - - name: increment-decrement - - name: modifies-parameter - - name: modifies-value-receiver - - name: package-comments - - name: range - - name: range-val-address - - name: range-val-in-closure - - name: receiver-naming - - name: redefines-builtin-id - - name: string-of-int - - name: struct-tag - - name: superfluous-else - - name: time-naming - - name: unconditional-recursion - - name: unexported-naming - - name: unnecessary-stmt - - name: unreachable-code - - name: var-declaration - - name: var-naming - - name: waitgroup-by-value - -issues: - exclude-dirs: - - docs - - api - - exclude-files: - - .*_test\.go$ - - exclude-rules: - - path: (.+)_test\.go - linters: - - gocyclo - - errcheck - - dupl - - gosec - - # The logic of creating a linter is similar between linters, it's not duplication. - #- path: pkg/golinters - # linters: - # - dupl - - # Deprecated configuration options. - #- path: pkg/commands/run.go - # linters: [staticcheck] - # text: "SA1019: c.cfg.Run.ShowStats is deprecated: use Output.ShowStats instead." - - # Deprecated linter options. - #- path: pkg/golinters/errcheck/errcheck.go - # linters: [staticcheck] - # text: "SA1019: errCfg.Exclude is deprecated: use ExcludeFunctions instead" - #- path: pkg/golinters/errcheck/errcheck.go - # linters: [staticcheck] - # text: "SA1019: errCfg.Ignore is deprecated: use ExcludeFunctions instead" - #- path: pkg/golinters/govet/govet.go - # linters: [staticcheck] - # text: "SA1019: cfg.CheckShadowing is deprecated: the linter should be enabled inside Enable." - #- path: pkg/golinters/godot/godot.go - # linters: [staticcheck] - # text: "SA1019: settings.CheckAll is deprecated: use Scope instead" - #- path: pkg/golinters/gci/gci.go - # linters: [staticcheck] - # text: "SA1019: settings.LocalPrefixes is deprecated: use Sections instead." - #- path: pkg/golinters/mnd/mnd.go - # linters: [staticcheck] - # text: "SA1019: settings.Settings is deprecated: use root level settings instead." - #- path: pkg/golinters/mnd/mnd.go - # linters: [staticcheck] - # text: "SA1019: config.GoMndSettings is deprecated: use MndSettings." - - # Related to `run.go`, it cannot be removed. - - path: pkg/golinters/gofumpt/gofumpt.go - linters: [staticcheck] - text: "SA1019: settings.LangVersion is deprecated: use the global `run.go` instead." - - path: pkg/golinters/internal/staticcheck_common.go - linters: [staticcheck] - text: "SA1019: settings.GoVersion is deprecated: use the global `run.go` instead." - - path: pkg/lint/lintersdb/manager.go - linters: [staticcheck] - text: "SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead." - - # Based on existing code, the modifications should be limited to make maintenance easier. - - path: pkg/golinters/unused/unused.go - linters: [gocritic] - text: "rangeValCopy: each iteration copies 160 bytes \\(consider pointers or indexing\\)" - - # Related to file sizes. - - path: pkg/goanalysis/runner_loadingpackage.go - linters: [gosec] - text: "G115: integer overflow conversion uintptr -> int" - - # Related to PID. - - path: test/bench/bench_test.go - linters: [gosec] - text: "G115: integer overflow conversion int -> int32" - - # Related to the result of computation but divided multiple times by 1024. - - path: test/bench/bench_test.go - linters: [gosec] - text: "G115: integer overflow conversion uint64 -> int" - -run: - # timeout for analysis, e.g. 30s, 5m, default is 1m - timeout: 5m - # include test files or not, default is true - tests: false - + # Service initialization deliberately owns command-line flag parsing. + - linters: + - revive + path: ^cmd/[^/]+/initial/initApp\.go$ + text: 'deep-exit: calls to flag.Parse' + # These public cipher APIs retain their existing ciphertext formats for compatibility. + - linters: + - staticcheck + path: pkg/gocrypto/rsa.go + text: 'SA1019: crypto/rsa\.(Encrypt|Decrypt)PKCS1v15' + - linters: + - staticcheck + path: pkg/gocrypto/wcipher/mode.go + text: 'SA1019: crypto/cipher\.New(CFBEncrypter|CFBDecrypter|OFB)' + # Migrating Director to Rewrite changes forwarding-header behavior; keep the current API behavior. + - linters: + - staticcheck + path: pkg/proxykit/backend.go + text: 'SA1019: \(net/http/httputil.ReverseProxy\).Director' + - linters: + - dupl + - errcheck + - gocyclo + - gosec + path: (.+)_test\.go + - linters: + - staticcheck + path: pkg/golinters/gofumpt/gofumpt.go + text: 'SA1019: settings.LangVersion is deprecated: use the global `run.go` instead.' + - linters: + - staticcheck + path: pkg/golinters/internal/staticcheck_common.go + text: 'SA1019: settings.GoVersion is deprecated: use the global `run.go` instead.' + - linters: + - staticcheck + path: pkg/lint/lintersdb/manager.go + text: 'SA1019: (.+).(GoVersion|LangVersion) is deprecated: use the global `run.go` instead.' + - linters: + - gocritic + path: pkg/golinters/unused/unused.go + text: 'rangeValCopy: each iteration copies 160 bytes \(consider pointers or indexing\)' + - linters: + - gosec + path: pkg/goanalysis/runner_loadingpackage.go + text: 'G115: integer overflow conversion uintptr -> int' + - linters: + - gosec + path: test/bench/bench_test.go + text: 'G115: integer overflow conversion int -> int32' + - linters: + - gosec + path: test/bench/bench_test.go + text: 'G115: integer overflow conversion uint64 -> int' + paths: + - .*_test\.go$ + - docs + - api + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - goimports + settings: + gofmt: + rewrite-rules: + - pattern: interface{} + replacement: any + goimports: + local-prefixes: + - github.com/go-dev-frame/sponge + exclusions: + generated: lax + paths: + - .*_test\.go$ + - docs + - api + - third_party$ + - builtin$ + - examples$ diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 00000000..7970662f --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,37 @@ +# Repository Guidelines + +## Project Structure & Module Organization + +Sponge is a Go code generator and Gin/gRPC framework. `cmd/sponge/` contains the CLI and generation UI; `cmd/protoc-gen-*/` contains Protobuf plugins. Reusable components live in `pkg/`. Service templates span `internal/` (handlers, services, DAO, models, configuration), `cmd/serverNameExample_*/`, and `api/` (Protobuf definitions and generated code). + +Tests sit beside Go sources as `*_test.go`. `test/auto-test/` holds generation checks, `test/server/` provides dependency services, and `test/sql/` contains fixtures. Configuration examples live in `configs/`, deployment files in `deployments/`, automation in `scripts/`, documentation in `docs/`, and images in `assets/`. Bundled UI assets live in `cmd/sponge/server/static/`. + +## Build, Test, and Development Commands + +Run commands from the repository root. `go.mod` and CI use Go 1.27.1. + +- `go build -o /tmp/sponge ./cmd/sponge`: build the CLI for your machine. +- `go run ./cmd/sponge run`: start the generation UI at `http://localhost:24631`. +- `make build-sponge`: cross-compile the CLI for Linux/amd64. +- `make build`: cross-compile the mixed HTTP/gRPC service template. +- `make test`: run uncached short tests, excluding `api/`, `cmd/`, and vendor packages. +- `make cover`: produce `cover.out` and open HTML coverage. +- `make ci-lint`: format Go files in place, then run GolangCI-Lint. Use v2.13.2 to match CI. + +## Coding Style & Naming Conventions + +Use Go formatting with tabs (`gofmt -s`) and `goimports`, grouping local imports under `github.com/go-dev-frame/sponge`. Follow `.golangci.yml`; its line-length limit is 200 characters. Use lowercase package names, exported `PascalCase` identifiers, and unexported `camelCase` identifiers. + +Preserve generator placeholders such as `serverNameExample` and `userExample`, template markers, and related `.tpl`, `.exp`, and `.mgo` variants. Regenerate Protobuf output with `make proto FILES=api/path/file.proto` after installing the required plugins. + +## Testing Guidelines + +Use Go's `testing` package and existing Testify assertions; database/cache tests use SQLMock and miniredis helpers. Name tests `TestXxx` in adjacent `*_test.go` files. Use `t.TempDir()` for temporary artifacts. Run focused tests with `go test -count=1 ./pkg/cache`. Test changed CLI packages explicitly because `make test` excludes them. + +Codecov targets 75% project coverage and 60% patch coverage; the patch target is informational. For generator changes, follow `test/auto-test/README.md` to validate generated services. + +## Commit & Pull Request Guidelines + +History commonly uses `feat:`, `fix:`, `docs:`, `build:`, `style:`, and `release:` prefixes, alongside imperative summaries. Prefer a concise, scoped subject such as `fix: handle empty query results`. + +Describe the problem, resulting behavior, related issues, and validation commands in PRs. Include screenshots for visible UI changes and generated-output examples for template changes. Keep related templates and documentation consistent. diff --git a/Makefile b/Makefile index b0f1626f..641d5f14 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ install: go install github.com/go-dev-frame/sponge/cmd/protoc-gen-go-rpc-tmpl@latest go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest - go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest + go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.2 go install github.com/swaggo/swag/cmd/swag@v1.8.12 go install github.com/ofabry/go-callvis@latest go install golang.org/x/pkgsite/cmd/pkgsite@latest @@ -27,6 +27,7 @@ install: # Check code formatting, naming conventions, security, maintainability, etc. the rules in the .golangci.yml file ci-lint: @gofmt -s -w . + golangci-lint fmt --diff golangci-lint run ./... diff --git a/Makefile-for-http b/Makefile-for-http index 4d811559..228ffc57 100644 --- a/Makefile-for-http +++ b/Makefile-for-http @@ -10,6 +10,7 @@ PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/ | grep -v /api/ | grep # Check the code specification against the rules in the .golangci.yml file ci-lint: @gofmt -s -w . + golangci-lint fmt --diff golangci-lint run ./... diff --git a/assets/install-cn.md b/assets/install-cn.md index 0b599af9..059a1c83 100644 --- a/assets/install-cn.md +++ b/assets/install-cn.md @@ -1,4 +1,4 @@ -要求 [Go 1.23+](https://studygolang.com/dl) 版本。 +要求 [Go 1.27.1+](https://studygolang.com/dl) 版本。 > **提示**:Go下载第三方包时可能会遇到依赖下载超时问题,建议设置国内代理: > ```bash diff --git a/assets/install-en.md b/assets/install-en.md index cb97889f..3667be99 100644 --- a/assets/install-en.md +++ b/assets/install-en.md @@ -1,4 +1,4 @@ -Requires [Go 1.23+](https://go.dev/doc/install) version. +Requires [Go 1.27.1+](https://go.dev/doc/install) version.
diff --git a/cmd/sponge/commands/generate/common.go b/cmd/sponge/commands/generate/common.go index baf0e088..2cd95ef8 100644 --- a/cmd/sponge/commands/generate/common.go +++ b/cmd/sponge/commands/generate/common.go @@ -27,8 +27,8 @@ import ( ) const ( - defaultGoModVersion = "go 1.23.0" - defaultImageGoModVersion = "golang:1.23-alpine" + defaultGoModVersion = "go 1.27.1" + defaultImageGoModVersion = "golang:1.27.1-alpine" // TplNameSponge name of the template TplNameSponge = "sponge" @@ -856,7 +856,7 @@ func getLocalGoVersion() string { func extractImageGoVersion() string { goVersion := getLocalGoVersion() - re := regexp.MustCompile(`go\s+(\d+\.\d+)\.\d+`) + re := regexp.MustCompile(`go\s+(\d+\.\d+(?:\.\d+)?)`) matches := re.FindStringSubmatch(goVersion) if len(matches) > 1 { return fmt.Sprintf("golang:%s-alpine", matches[1]) diff --git a/cmd/sponge/commands/generate/common_test.go b/cmd/sponge/commands/generate/common_test.go new file mode 100644 index 00000000..8b007ee1 --- /dev/null +++ b/cmd/sponge/commands/generate/common_test.go @@ -0,0 +1,42 @@ +package generate + +import ( + "os" + "path/filepath" + "runtime" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestGeneratedGoVersions(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("the mock go command is a shell script") + } + + tests := []struct { + name string + version string + wantModule string + wantImage string + }{ + {"missing toolchain", "", defaultGoModVersion, defaultImageGoModVersion}, + {"older toolchain", "go1.26.4", defaultGoModVersion, defaultImageGoModVersion}, + {"matching toolchain", "go1.27.1", "go 1.27.1", "golang:1.27.1-alpine"}, + {"newer patch", "go1.27.2", "go 1.27.2", "golang:1.27.2-alpine"}, + {"newer minor", "go1.28.0", "go 1.28.0", "golang:1.28.0-alpine"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + dir := t.TempDir() + if tt.version != "" { + script := "#!/bin/sh\necho 'go version " + tt.version + " linux/amd64'\n" + require.NoError(t, os.WriteFile(filepath.Join(dir, "go"), []byte(script), 0755)) + } + t.Setenv("PATH", dir) + + require.Equal(t, tt.wantModule, getLocalGoVersion()) + require.Equal(t, tt.wantImage, extractImageGoVersion()) + }) + } +} diff --git a/cmd/sponge/commands/plugins.go b/cmd/sponge/commands/plugins.go index 786870ba..80607bf4 100644 --- a/cmd/sponge/commands/plugins.go +++ b/cmd/sponge/commands/plugins.go @@ -44,7 +44,7 @@ var installPluginCommands = map[string]string{ "protoc-gen-openapiv2": "github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest", "protoc-gen-doc": "github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@latest", "swag": "github.com/swaggo/swag/cmd/swag@v1.8.12", - //"golangci-lint": "github.com/golangci/golangci-lint/cmd/golangci-lint@latest", + //"golangci-lint": "github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.13.2", //"go-callvis": "github.com/ofabry/go-callvis@latest", } diff --git a/go.mod b/go.mod index 0ede408b..d71b08e7 100644 --- a/go.mod +++ b/go.mod @@ -1,13 +1,13 @@ module github.com/go-dev-frame/sponge -go 1.23.0 +go 1.27.1 require ( github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/IBM/sarama v1.43.2 github.com/alicebob/miniredis/v2 v2.23.0 github.com/bojand/ghz v0.120.0 - github.com/bytedance/sonic v1.14.0 + github.com/bytedance/sonic v1.15.2 github.com/dgraph-io/ristretto v0.2.0 github.com/fatih/color v1.13.0 github.com/felixge/fgprof v0.9.3 @@ -71,9 +71,9 @@ require ( gorm.io/driver/mysql v1.5.7 gorm.io/driver/postgres v1.5.4 gorm.io/driver/sqlite v1.5.4 - gorm.io/gorm v1.30.0 + gorm.io/gorm v1.30.3 gorm.io/plugin/dbresolver v1.6.0 - // todo generate the local sponge template code version here +// todo generate the local sponge template code version here ) require ( @@ -103,10 +103,11 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/bufbuild/protocompile v0.4.0 // indirect github.com/buger/jsonparser v1.1.1 // indirect - github.com/bytedance/sonic/loader v0.3.0 // indirect + github.com/bytedance/gopkg v0.1.3 // indirect + github.com/bytedance/sonic/loader v0.5.1 // indirect github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/cloudwego/base64x v0.1.5 // indirect + github.com/cloudwego/base64x v0.1.6 // indirect github.com/cncf/xds/go v0.0.0-20240723142845-024c85f92f20 // indirect github.com/coreos/go-semver v0.3.0 // indirect github.com/coreos/go-systemd/v22 v22.3.2 // indirect @@ -170,7 +171,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/juju/errors v1.0.0 // indirect github.com/klauspost/compress v1.17.8 // indirect - github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/klauspost/cpuid/v2 v2.2.9 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect github.com/magiconair/properties v1.8.6 // indirect diff --git a/go.sum b/go.sum index e1974a19..dbb56186 100644 --- a/go.sum +++ b/go.sum @@ -117,11 +117,12 @@ github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZ github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8= github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= -github.com/bytedance/sonic v1.14.0 h1:/OfKt8HFw0kh2rj8N0F6C/qPGRESq0BbaNZgcNXXzQQ= -github.com/bytedance/sonic v1.14.0/go.mod h1:WoEbx8WTcFJfzCe0hbmyTGrfjt8PzNEBdxlNUO24NhA= -github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= -github.com/bytedance/sonic/loader v0.3.0 h1:dskwH8edlzNMctoruo8FPTJDF3vLtDT0sXZwvZJyqeA= -github.com/bytedance/sonic/loader v0.3.0/go.mod h1:N8A3vUdtUebEY2/VQC0MyhYeKUFosQU6FxH2JmUe6VI= +github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= +github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= +github.com/bytedance/sonic v1.15.2 h1:90H+rcF/FwLXwfB1cudOLq/je83n683Utf4Cbp0xHCo= +github.com/bytedance/sonic v1.15.2/go.mod h1:mT2NbXunuaEbnZ+mRIX/vYqKISmgEuHFDI4UzmKx2SA= +github.com/bytedance/sonic/loader v0.5.1 h1:Ygpfa9zwRCCKSlrp5bBP/b/Xzc3VxsAW+5NIYXrOOpI= +github.com/bytedance/sonic/loader v0.5.1/go.mod h1:AR4NYCk5DdzZizZ5djGqQ92eEhCCcdf5x77udYiSJRo= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= @@ -134,9 +135,8 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMn github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag= github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= -github.com/cloudwego/base64x v0.1.5 h1:XPciSp1xaq2VCSt6lF0phncD4koWyULpl5bUxbfCyP4= -github.com/cloudwego/base64x v0.1.5/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= -github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= +github.com/cloudwego/base64x v0.1.6 h1:t11wG9AECkCDk5fMSoxmufanudBtJ+/HemLstXDLI2M= +github.com/cloudwego/base64x v0.1.6/go.mod h1:OFcloc187FXDaYHvrNIjxSe8ncn0OOM8gEHfghB2IPU= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk= @@ -473,10 +473,8 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= -github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= -github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= -github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= +github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY= +github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -1188,8 +1186,8 @@ gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C gorm.io/driver/sqlite v1.5.4 h1:IqXwXi8M/ZlPzH/947tn5uik3aYQslP9BVveoax0nV0= gorm.io/driver/sqlite v1.5.4/go.mod h1:qxAuCol+2r6PannQDpOP1FP6ag3mKi4esLnB/jHed+4= gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= -gorm.io/gorm v1.30.0 h1:qbT5aPv1UH8gI99OsRlvDToLxW5zR7FzS9acZDOZcgs= -gorm.io/gorm v1.30.0/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= +gorm.io/gorm v1.30.3 h1:QiG8upl0Sg9ba2Zatfjy0fy4It2iNBL2/eMdvEkdXNs= +gorm.io/gorm v1.30.3/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= gorm.io/plugin/dbresolver v1.6.0 h1:XvKDeOtTn1EIX6s4SrKpEH82q0gXVemhYjbYZFGFVcw= gorm.io/plugin/dbresolver v1.6.0/go.mod h1:tctw63jdrOezFR9HmrKnPkmig3m5Edem9fdxk9bQSzM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= @@ -1199,7 +1197,6 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= -nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA= diff --git a/internal/dao/userExample.go.exp b/internal/dao/userExample.go.exp index 76915207..23556d87 100644 --- a/internal/dao/userExample.go.exp +++ b/internal/dao/userExample.go.exp @@ -3,7 +3,6 @@ package dao import ( "context" "errors" - "time" "golang.org/x/sync/singleflight" "gorm.io/gorm" @@ -336,10 +335,7 @@ func (d *userExampleDao) CreateByTx(ctx context.Context, tx *gorm.DB, table *mod // DeleteByTx delete a record by id in the database using the provided transaction func (d *userExampleDao) DeleteByTx(ctx context.Context, tx *gorm.DB, id uint64) error { - update := map[string]interface{}{ - "deleted_at": time.Now(), - } - err := tx.WithContext(ctx).Model(&model.UserExample{}).Where("id = ?", id).Updates(update).Error + err := tx.WithContext(ctx).Where("id = ?", id).Delete(&model.UserExample{}).Error if err != nil { return err } diff --git a/internal/dao/userExample_test.go.exp b/internal/dao/userExample_test.go.exp index 16f16985..bc208980 100644 --- a/internal/dao/userExample_test.go.exp +++ b/internal/dao/userExample_test.go.exp @@ -60,10 +60,11 @@ func Test_userExampleDao_DeleteByID(t *testing.T) { defer d.Close() testData := d.TestData.(*model.UserExample) expectedSQLForDeletion := "UPDATE .*" + expectedArgsForDeletionTime := d.AnyTime d.SQLMock.ExpectBegin() d.SQLMock.ExpectExec(expectedSQLForDeletion). - WithArgs(d.AnyTime, testData.ID). + WithArgs(expectedArgsForDeletionTime, testData.ID). WillReturnResult(sqlmock.NewResult(int64(testData.ID), 1)) d.SQLMock.ExpectCommit() @@ -199,14 +200,16 @@ func Test_userExampleDao_DeleteByIDs(t *testing.T) { d := newUserExampleDao() defer d.Close() testData := d.TestData.(*model.UserExample) + expectedSQLForDeletion := "UPDATE .*" + expectedArgsForDeletionTime := d.AnyTime d.SQLMock.ExpectBegin() - d.SQLMock.ExpectExec("UPDATE .*"). - WithArgs(d.AnyTime, testData.ID). + d.SQLMock.ExpectExec(expectedSQLForDeletion). + WithArgs(expectedArgsForDeletionTime, testData.ID). WillReturnResult(sqlmock.NewResult(int64(testData.ID), 1)) d.SQLMock.ExpectCommit() - err := d.IDao.(UserExampleDao).DeleteByID(d.Ctx, testData.ID) + err := d.IDao.(UserExampleDao).DeleteByIDs(d.Ctx, []uint64{testData.ID}) if err != nil { t.Fatal(err) } @@ -226,7 +229,7 @@ func Test_userExampleDao_GetByCondition(t *testing.T) { AddRow(testData.ID) d.SQLMock.ExpectQuery("SELECT .*"). - WithArgs(testData.ID). + WithArgs(testData.ID, 1). WillReturnRows(rows) _, err := d.IDao.(UserExampleDao).GetByCondition(d.Ctx, &query.Conditions{ @@ -334,10 +337,11 @@ func Test_userExampleDao_DeleteByTx(t *testing.T) { defer d.Close() testData := d.TestData.(*model.UserExample) expectedSQLForDeletion := "UPDATE .*" + expectedArgsForDeletionTime := d.AnyTime d.SQLMock.ExpectBegin() d.SQLMock.ExpectExec(expectedSQLForDeletion). - WithArgs(d.AnyTime, testData.ID). + WithArgs(expectedArgsForDeletionTime, testData.ID). WillReturnResult(sqlmock.NewResult(int64(testData.ID), 1)) d.SQLMock.ExpectCommit() diff --git a/internal/handler/userExample_test.go.exp b/internal/handler/userExample_test.go.exp index 2a95b7ef..bd239f75 100644 --- a/internal/handler/userExample_test.go.exp +++ b/internal/handler/userExample_test.go.exp @@ -286,10 +286,12 @@ func Test_userExampleHandler_DeleteByIDs(t *testing.T) { h := newUserExampleHandler() defer h.Close() testData := h.TestData.(*model.UserExample) + expectedSQLForDeletion := "UPDATE .*" + expectedArgsForDeletionTime := h.MockDao.AnyTime h.MockDao.SQLMock.ExpectBegin() - h.MockDao.SQLMock.ExpectExec("UPDATE .*"). - WithArgs(h.MockDao.AnyTime, testData.ID). // adjusted for the amount of test data + h.MockDao.SQLMock.ExpectExec(expectedSQLForDeletion). + WithArgs(expectedArgsForDeletionTime, testData.ID). // adjusted for the amount of test data WillReturnResult(sqlmock.NewResult(int64(testData.ID), 1)) h.MockDao.SQLMock.ExpectCommit() diff --git a/pkg/aicli/chatgpt/client_test.go b/pkg/aicli/chatgpt/client_test.go index 4dd0c964..f868f374 100644 --- a/pkg/aicli/chatgpt/client_test.go +++ b/pkg/aicli/chatgpt/client_test.go @@ -46,7 +46,7 @@ func TestClient_SendStream(t *testing.T) { ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) reply := client.SendStream(ctx, "Which model did you use to answer the question?") for content := range reply.Content { - fmt.Printf(content) + fmt.Print(content) } if reply.Err != nil { t.Log(reply.Err) diff --git a/pkg/aicli/deepseek/client_test.go b/pkg/aicli/deepseek/client_test.go index 315e6eae..37bdcfb8 100644 --- a/pkg/aicli/deepseek/client_test.go +++ b/pkg/aicli/deepseek/client_test.go @@ -46,7 +46,7 @@ func TestClient_SendStream(t *testing.T) { ctx, _ := context.WithTimeout(context.Background(), 10*time.Second) answer := client.SendStream(ctx, genericRoleDescZH) for content := range answer.Content { - fmt.Printf(content) + fmt.Print(content) } if answer.Err != nil { t.Log(answer.Err) diff --git a/pkg/aicli/gemini/client_test.go b/pkg/aicli/gemini/client_test.go index 82d2cd2a..153d3d0f 100644 --- a/pkg/aicli/gemini/client_test.go +++ b/pkg/aicli/gemini/client_test.go @@ -41,7 +41,7 @@ func TestClient_SendStream(t *testing.T) { ctx, _ := context.WithTimeout(context.Background(), 5*time.Second) reply := client.SendStream(ctx, "Which model did you use to answer the question?") for content := range reply.Content { - fmt.Printf(content) + fmt.Print(content) } if reply.Err != nil { t.Log(reply.Err) diff --git a/pkg/conf/parse.go b/pkg/conf/parse.go index 9491736c..968e7822 100644 --- a/pkg/conf/parse.go +++ b/pkg/conf/parse.go @@ -18,7 +18,7 @@ import ( // Parse configuration files to struct, including yaml, toml, json, etc., and turn on listening for configuration file changes if fs is not empty func Parse(configFile string, obj interface{}, reloads ...func()) error { v := reflect.ValueOf(obj) - if v.Kind() != reflect.Ptr || v.IsNil() { + if v.Kind() != reflect.Pointer || v.IsNil() { return fmt.Errorf("obj must be a non-nil pointer") } diff --git a/pkg/conf/parse_test.go b/pkg/conf/parse_test.go index f59a457b..a55b238a 100644 --- a/pkg/conf/parse_test.go +++ b/pkg/conf/parse_test.go @@ -27,10 +27,10 @@ func Test_hideSensitiveFields(t *testing.T) { keywords = append(keywords, `"dsn"`, `"password"`, `"name"`) str := Show(c, keywords...) - fmt.Printf(hideSensitiveFields(str)) + fmt.Print(hideSensitiveFields(str)) str = "\ndefault:123456@192.168.3.37:6379/0\n" - fmt.Printf(hideSensitiveFields(str)) + fmt.Print(hideSensitiveFields(str)) } // test listening for configuration file updates diff --git a/pkg/encoding/encoding.go b/pkg/encoding/encoding.go index 6b74dc1b..1021bea9 100644 --- a/pkg/encoding/encoding.go +++ b/pkg/encoding/encoding.go @@ -111,7 +111,7 @@ func Unmarshal(e Encoding, data []byte, v interface{}) (err error) { func isPointer(data interface{}) bool { switch reflect.ValueOf(data).Kind() { - case reflect.Ptr, reflect.Interface: + case reflect.Pointer, reflect.Interface: return true default: return false diff --git a/pkg/encoding/json/json.go b/pkg/encoding/json/json.go index 0f5e1109..5734a5ff 100644 --- a/pkg/encoding/json/json.go +++ b/pkg/encoding/json/json.go @@ -53,7 +53,7 @@ func (codec) Unmarshal(data []byte, v interface{}) error { return UnmarshalOptions.Unmarshal(data, m) default: rv := reflect.ValueOf(v) - for rv := rv; rv.Kind() == reflect.Ptr; { + for rv := rv; rv.Kind() == reflect.Pointer; { if rv.IsNil() { rv.Set(reflect.New(rv.Type().Elem())) } diff --git a/pkg/gin/validator/validator.go b/pkg/gin/validator/validator.go index 49216536..33b653b1 100644 --- a/pkg/gin/validator/validator.go +++ b/pkg/gin/validator/validator.go @@ -33,7 +33,7 @@ func (v *CustomValidator) ValidateStruct(obj interface{}) error { } val := reflect.ValueOf(obj) - if val.Kind() == reflect.Ptr { + if val.Kind() == reflect.Pointer { val = val.Elem() } @@ -43,7 +43,7 @@ func (v *CustomValidator) ValidateStruct(obj interface{}) error { return err } - case reflect.Ptr: + case reflect.Pointer: // pointer type: if nil, no validation required; otherwise recursive validation after dereference if val.IsNil() { return nil diff --git a/pkg/gobash/gobash_test.go b/pkg/gobash/gobash_test.go index 2ae5c091..40c26ada 100644 --- a/pkg/gobash/gobash_test.go +++ b/pkg/gobash/gobash_test.go @@ -25,7 +25,7 @@ func TestRun(t *testing.T) { t.Logf("pid: %d", pid) continue } - t.Logf(v) + t.Log(v) } if result.Err != nil { t.Logf("execute command failed, %v", result.Err) diff --git a/pkg/gotest/dao.go b/pkg/gotest/dao.go index 841f02b4..5ad0afa3 100644 --- a/pkg/gotest/dao.go +++ b/pkg/gotest/dao.go @@ -79,7 +79,7 @@ func (d *Dao) GetAnyArgs(obj interface{}) []driver.Value { vo := reflect.ValueOf(obj) //nolint - if to.Kind() == reflect.Ptr { + if to.Kind() == reflect.Pointer { if vo.IsNil() { panic("nil ptr") } diff --git a/pkg/sgorm/base_model.go b/pkg/sgorm/base_model.go index ce504299..76b5141a 100644 --- a/pkg/sgorm/base_model.go +++ b/pkg/sgorm/base_model.go @@ -51,7 +51,7 @@ func GetTableName(object interface{}) string { typeof := reflect.TypeOf(object) switch typeof.Kind() { - case reflect.Ptr: + case reflect.Pointer: tableName = typeof.Elem().Name() case reflect.Struct: tableName = typeof.Name() diff --git a/pkg/sgorm/sqlite/sqlite_test.go b/pkg/sgorm/sqlite/sqlite_test.go index 0f390cec..328edc76 100644 --- a/pkg/sgorm/sqlite/sqlite_test.go +++ b/pkg/sgorm/sqlite/sqlite_test.go @@ -1,6 +1,7 @@ package sqlite import ( + "path/filepath" "testing" "time" @@ -8,7 +9,7 @@ import ( ) func TestInit(t *testing.T) { - dbFile := "test_sqlite.db" + dbFile := filepath.Join(t.TempDir(), "test_sqlite.db") db, err := Init(dbFile) if err != nil { // ignore test error about not being able to connect to real sqlite diff --git a/pkg/sgorm/sqlite/test_sqlite.db b/pkg/sgorm/sqlite/test_sqlite.db deleted file mode 100644 index 3d6d9e3d..00000000 Binary files a/pkg/sgorm/sqlite/test_sqlite.db and /dev/null differ diff --git a/pkg/sql2code/parser/nameFormat.go b/pkg/sql2code/parser/nameFormat.go index 74ca60b8..ecf41562 100644 --- a/pkg/sql2code/parser/nameFormat.go +++ b/pkg/sql2code/parser/nameFormat.go @@ -95,7 +95,7 @@ func customToCamel(str string) string { func customToSnake(str string) string { str = toCamel(str) l := len(str) - for k, _ := range peculiarNouns { + for k := range peculiarNouns { if str == k { str = strings.ToLower(str) break diff --git a/pkg/sql2code/parser/parser_test.go b/pkg/sql2code/parser/parser_test.go index d6a5d517..afcf46e1 100644 --- a/pkg/sql2code/parser/parser_test.go +++ b/pkg/sql2code/parser/parser_test.go @@ -2,6 +2,7 @@ package parser import ( "fmt" + "path/filepath" "testing" "github.com/jinzhu/inflection" @@ -368,7 +369,8 @@ func Test_getPostgresqlTableFields(t *testing.T) { } func TestGetSqliteTableInfo(t *testing.T) { - info, err := GetSqliteTableInfo("..\\..\\..\\test\\sql\\sqlite\\sponge.db", "user_order") + dbFile := filepath.Join("..", "..", "..", "test", "sql", "sqlite", "sponge.db") + info, err := GetSqliteTableInfo(dbFile, "user_order") t.Log(err, info) } diff --git a/pkg/tracer/console_test.go b/pkg/tracer/console_test.go index 7971fbf4..e446be66 100644 --- a/pkg/tracer/console_test.go +++ b/pkg/tracer/console_test.go @@ -14,13 +14,25 @@ func TestNewConsoleExporter(t *testing.T) { } func TestNewFileExporter(t *testing.T) { + wd, err := os.Getwd() + if err != nil { + t.Fatal(err) + } + if err := os.Chdir(t.TempDir()); err != nil { + t.Fatal(err) + } + defer func() { + if err := os.Chdir(wd); err != nil { + t.Fatal(err) + } + }() + exporter, file, err := NewFileExporter("demo") if err != nil { t.Fatal(err) } assert.NotNil(t, exporter) _ = file.Close() - _ = os.RemoveAll("demo") exporter, file, err = NewFileExporter("") if err != nil { @@ -28,15 +40,10 @@ func TestNewFileExporter(t *testing.T) { } assert.NotNil(t, exporter) _ = file.Close() - _ = os.RemoveAll("traces.json") - defer func() { - recover() - }() - _, _, err = NewFileExporter("\\\\") - if err != nil { - t.Fatal(err) - } + assert.Panics(t, func() { + _, _, _ = NewFileExporter(t.TempDir()) + }) } func Test_newExporter(t *testing.T) { diff --git a/scripts/build/Dockerfile_build b/scripts/build/Dockerfile_build index 2fa53b7b..d506d48e 100644 --- a/scripts/build/Dockerfile_build +++ b/scripts/build/Dockerfile_build @@ -1,7 +1,7 @@ # Need to package the code first `tar zcf serverNameExample.tar.gz $(ls)` and move it to the same directory as Dokerfile # Compile the go code, you can specify the golang version -FROM golang:1.23-alpine as build +FROM golang:1.27.1-alpine as build COPY . /go/src/serverNameExample WORKDIR /go/src/serverNameExample RUN tar zxf serverNameExample.tar.gz diff --git a/scripts/build/Dockerfile_test b/scripts/build/Dockerfile_test index 6549dc32..170644a0 100644 --- a/scripts/build/Dockerfile_test +++ b/scripts/build/Dockerfile_test @@ -1,6 +1,6 @@ # Need to package the code first `tar zcf serverNameExample.tar.gz $(ls)` and move it to the same directory as Dokerfile # rpc server source code, used to test rpc methods -FROM golang:1.23-alpine +FROM golang:1.27.1-alpine MAINTAINER zhufuyi "g.zhufuyi@gmail.com" # go test dependency packages diff --git a/test/server/jenkins/Dockerfile b/test/server/jenkins/Dockerfile index 69cb57da..d2e04a14 100644 --- a/test/server/jenkins/Dockerfile +++ b/test/server/jenkins/Dockerfile @@ -5,9 +5,9 @@ USER root RUN apt-get update -y && apt-get dist-upgrade -y && apt-get install -y apt-utils make RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone -RUN curl -L -o go1.19.tar.gz https://studygolang.com/dl/golang/go1.19.1.linux-amd64.tar.gz \ - && tar zxf go1.19.tar.gz \ - && rm -f go1.19.tar.gz \ +RUN curl -L -o go1.27.1.tar.gz https://go.dev/dl/go1.27.1.linux-amd64.tar.gz \ + && tar zxf go1.27.1.tar.gz \ + && rm -f go1.27.1.tar.gz \ && mv -f go /opt/ RUN echo 'export GOROOT="/opt/go"' >> ~/.bashrc \