From 1ba77f8ed48cd4d32d44438dd98b7aa66d863379 Mon Sep 17 00:00:00 2001 From: tobin Date: Thu, 6 Nov 2025 12:44:24 +0800 Subject: [PATCH 1/4] chore: upgrade v8go --- go.mod | 6 +++++- go.sum | 12 ++++++++++-- pkg/runner/libs.go | 2 +- pkg/runner/runner.go | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 3c83df4..39a88ae 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.21 require ( github.com/rs/zerolog v1.31.0 github.com/stretchr/testify v1.8.4 - rogchap.com/v8go v0.9.0 + github.com/stumble/v8go v0.33.1 ) require ( @@ -13,6 +13,10 @@ require ( github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/stumble/v8go/deps/darwin_amd64 v0.0.0-20250618204609-b802926d07ec // indirect + github.com/stumble/v8go/deps/darwin_arm64 v0.0.0-20250618204609-b802926d07ec // indirect + github.com/stumble/v8go/deps/linux_amd64 v0.0.0-20250618204609-b802926d07ec // indirect + github.com/stumble/v8go/deps/linux_arm64 v0.0.0-20250618204609-b802926d07ec // indirect golang.org/x/sys v0.12.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 8da63c5..844300e 100644 --- a/go.sum +++ b/go.sum @@ -15,6 +15,16 @@ github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A= github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stumble/v8go v0.33.1 h1:QEuQYM8pY0EunMGgX4PxynkPZbcE7nbr20VX3L0t7c8= +github.com/stumble/v8go v0.33.1/go.mod h1:/nhZqeF2CFSQJT8t+OAKAjY47HYKgiXpHUyQbuNL+WQ= +github.com/stumble/v8go/deps/darwin_amd64 v0.0.0-20250618204609-b802926d07ec h1:SB3uU+OLEooq5xOQztnunCIbCldYisNbgBE+fC6oCgo= +github.com/stumble/v8go/deps/darwin_amd64 v0.0.0-20250618204609-b802926d07ec/go.mod h1:CfTdhtoHTAglgJBYEHiRpWzn1O8+nl8SvhNb+3gnBdY= +github.com/stumble/v8go/deps/darwin_arm64 v0.0.0-20250618204609-b802926d07ec h1:JcU1imEKLQnvVPQ444Nl44SNFy69ineoBjXPF8VQ8LI= +github.com/stumble/v8go/deps/darwin_arm64 v0.0.0-20250618204609-b802926d07ec/go.mod h1:6ngHNiucZLWKJXTx5nVtPohpLiERKp5D3U8maklNFTM= +github.com/stumble/v8go/deps/linux_amd64 v0.0.0-20250618204609-b802926d07ec h1:Wxw+xJCuHEfHROeTas7oPh/u+XPgBUX4ndKYTET2h0E= +github.com/stumble/v8go/deps/linux_amd64 v0.0.0-20250618204609-b802926d07ec/go.mod h1:1LCvu+CMQM5Ir3XTmM+MyLo3GPbyiB0bNlUtHeOtCE8= +github.com/stumble/v8go/deps/linux_arm64 v0.0.0-20250618204609-b802926d07ec h1:q5+REIAziksb6S7ALAgQf2fU/YylYojz/LcuU+zDOmM= +github.com/stumble/v8go/deps/linux_arm64 v0.0.0-20250618204609-b802926d07ec/go.mod h1:UC/yWpaXMqESvLouqUU0bubKx3hJtfIxaEwmitww9+s= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= @@ -23,5 +33,3 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -rogchap.com/v8go v0.9.0 h1:wYbUCO4h6fjTamziHrzyrPnpFNuzPpjZY+nfmZjNaew= -rogchap.com/v8go v0.9.0/go.mod h1:MxgP3pL2MW4dpme/72QRs8sgNMmM0pRc8DPhcuLWPAs= diff --git a/pkg/runner/libs.go b/pkg/runner/libs.go index 635e4c0..73df208 100644 --- a/pkg/runner/libs.go +++ b/pkg/runner/libs.go @@ -1,7 +1,7 @@ package runner import ( - v8 "rogchap.com/v8go" + v8 "github.com/stumble/v8go" "github.com/stumble/v8runner/pkg/types" ) diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index bcbd425..f782f99 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -5,7 +5,7 @@ import ( "fmt" "strings" - v8 "rogchap.com/v8go" + v8 "github.com/stumble/v8go" ) var ( From c1f82d4ae1b64afcfe77ff9bd99556f1eb2bdd5f Mon Sep 17 00:00:00 2001 From: tobin Date: Thu, 6 Nov 2025 15:02:29 +0800 Subject: [PATCH 2/4] upgrade lint config --- .github/workflows/go.yml | 2 +- .golangci.yml | 145 ++++++++++++++--------------- cmd/example/runjsfile/runjsfile.go | 5 +- go.mod | 2 +- pkg/procrunner/procrunner.go | 2 +- 5 files changed, 75 insertions(+), 81 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index c4c85cc..c25a6da 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -23,7 +23,7 @@ jobs: go-version: '1.21' - name: Run golangci-lint - uses: golangci/golangci-lint-action@v3.7.0 + uses: golangci/golangci-lint-action@v7 - name: Build run: go build -v ./... diff --git a/.golangci.yml b/.golangci.yml index ceadb40..11f871f 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,93 +1,84 @@ +# The only possible value is "2". +version: "2" + # Options for analysis running. run: - timeout: 5m + timeout: 10m # # Which dirs to skip: issues from them won't be reported. # Can use regexp here: `generated.*`, regexp is applied on full path. # Default value is empty list, # but default dirs are skipped independently of this option's value (see skip-dirs-use-default). # "/" will be replaced by current OS file path separator to properly work on Windows. - skip-dirs: - - build - - dist - # modules-download-mode: vendor + modules-download-mode: mod # + go: '1.24' linters: - disable: - # a subset of unused (and with some weird bugs). - - deadcode - - structcheck - - varcheck - enable: + enable: # - asciicheck - bodyclose - dogsled - # next-time - # - dupl - - errcheck - - exportloopref - # - funlen - # - gochecknoglobals - # - gochecknoinits - # - gocognit + - copyloopvar - goconst - # - gocritic - # - gocyclo - # - godox - - gofmt - # - goimports - - gci - # next-time - # - revive - gosec - - gosimple - - govet - - ineffassign - # - interfacer - # - lll - # - maligned - - misspell - # - nakedret - # - nolintlint - # next-next-time - # - prealloc - - staticcheck - # next-time - # - stylecheck - - typecheck - unconvert - # - unparam - - unused - # - whitespace - # - wsl - -issues: - exclude-rules: - - path: _test\.go - linters: - - gosec - - unused - - goconst + - misspell + - reassign + - mirror + - durationcheck + - whitespace + - usetesting + - bidichk + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + rules: + - path: _test\.go + linters: + - gosec + paths: + - pkg/generated + - pkg/internal + - pkg/model + settings: + staticcheck: + checks: + - all + - -S1039 + - -ST1000 + - -ST1003 + - -ST1016 + - -ST1020 + - -ST1021 + - -ST1022 + dogsled: + max-blank-identifiers: 3 + misspell: + locale: US + -linters-settings: - gosimple: - checks: ["all", "-ST1000", "-ST1003", "-ST1016", "-ST1020", "-ST1021", "-ST1022", "-S1039"] - dogsled: - max-blank-identifiers: 3 - golint: - min-confidence: 0 - maligned: - suggest-new: true - misspell: - locale: US - gci: - # Section configuration to compare against. - # Section names are case-insensitive and may contain parameters in (). - # Default: ["standard", "default"] - sections: - - standard # Captures all standard packages if they do not match another section. - - default # Contains all imports that could not be matched to another section type. - - prefix(github.com/stumble/v8runner) # our internal packages - # Separators that should be present between sections. - # Default: ["newLine"] - section-separators: - - newLine \ No newline at end of file +formatters: + # Enable specific formatter. + # Default: [] (uses standard Go formatting) + enable: + - gci + - gofmt + - gofumpt + - goimports + - golines + settings: + gci: + # Section configuration to compare against. + # Section names are case-insensitive and may contain parameters in (). + # Default: ["standard", "default"] + sections: + - standard # Captures all standard packages if they do not match another section. + - default # Contains all imports that could not be matched to another section type. + - prefix(github.com/ggsrc) # our internal packages + - prefix(github.com/NFTGalaxy) # our internal packages + - prefix(github.com/NFTGalaxy/galaxy-graphigo) # local + # Separators that should be present between sections. + # Default: ["newLine"] + custom-order: true \ No newline at end of file diff --git a/cmd/example/runjsfile/runjsfile.go b/cmd/example/runjsfile/runjsfile.go index bf29a21..7a502fa 100644 --- a/cmd/example/runjsfile/runjsfile.go +++ b/cmd/example/runjsfile/runjsfile.go @@ -12,11 +12,14 @@ import ( // readFileToString reads the contents of the file specified by filename // and returns it as a string. func readFileToString(filename string) (string, error) { + // #nosec G304 -- This is an example program that intentionally opens user-specified files file, err := os.Open(filename) if err != nil { return "", err } - defer file.Close() + defer func() { + _ = file.Close() + }() bytes, err := io.ReadAll(file) if err != nil { diff --git a/go.mod b/go.mod index 39a88ae..3628825 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/stumble/v8runner -go 1.21 +go 1.24 require ( github.com/rs/zerolog v1.31.0 diff --git a/pkg/procrunner/procrunner.go b/pkg/procrunner/procrunner.go index ecac9fb..8cf1367 100644 --- a/pkg/procrunner/procrunner.go +++ b/pkg/procrunner/procrunner.go @@ -172,7 +172,7 @@ func (r *ProcRunner) RunCodeJSON(ctx context.Context, code string) (string, erro return } if res.Error != nil { - errs <- fmt.Errorf(*res.Error) + errs <- fmt.Errorf("%s", *res.Error) return } if res.ID != req.ID { From 9561cb35f4a80ec88673dc809c6fad4aad64962b Mon Sep 17 00:00:00 2001 From: tobin Date: Thu, 6 Nov 2025 15:33:31 +0800 Subject: [PATCH 3/4] fix lint --- cmd/example/memtest/memtest.go | 5 ++++- cmd/example/runcode/runcode.go | 5 ++++- pkg/procrunner/pool.go | 4 +--- pkg/procrunner/procrunner.go | 9 +++++++-- pkg/runner/libs.go | 1 - pkg/runner/reader_runner.go | 7 ++++++- pkg/runner/reader_runner_test.go | 1 - pkg/runner/runner.go | 4 +--- 8 files changed, 23 insertions(+), 13 deletions(-) diff --git a/cmd/example/memtest/memtest.go b/cmd/example/memtest/memtest.go index 30ed663..81727a3 100644 --- a/cmd/example/memtest/memtest.go +++ b/cmd/example/memtest/memtest.go @@ -17,7 +17,10 @@ func runApplyInt64() { } defer runner.Close() ctx := context.Background() - _, err = runner.RunCodeJSON(ctx, `let f = function(data){ return data.a + data.b === 579 ? 111 : 0; }`) + _, err = runner.RunCodeJSON( + ctx, + `let f = function(data){ return data.a + data.b === 579 ? 111 : 0; }`, + ) if err != nil { panic(err) } diff --git a/cmd/example/runcode/runcode.go b/cmd/example/runcode/runcode.go index 56c7cde..ced9adb 100644 --- a/cmd/example/runcode/runcode.go +++ b/cmd/example/runcode/runcode.go @@ -16,7 +16,10 @@ func main() { } defer runner.Close() - res, err := runner.RunCodeJSON(context.Background(), "const f = (data) => { return {a: data.X, b: data.Y} };") + res, err := runner.RunCodeJSON( + context.Background(), + "const f = (data) => { return {a: data.X, b: data.Y} };", + ) if err != nil { panic(err) } diff --git a/pkg/procrunner/pool.go b/pkg/procrunner/pool.go index 9ac279e..23561cb 100644 --- a/pkg/procrunner/pool.go +++ b/pkg/procrunner/pool.go @@ -5,9 +5,7 @@ import ( "sync" ) -var ( - ErrMaxReached = fmt.Errorf("max reached") -) +var ErrMaxReached = fmt.Errorf("max reached") // ProcRunnerPool is a manager that manages a pool of ProcRunner. // It can safely enforce the global memory limit by limiting the number of concurrent ProcRunners. diff --git a/pkg/procrunner/procrunner.go b/pkg/procrunner/procrunner.go index 8cf1367..e26a901 100644 --- a/pkg/procrunner/procrunner.go +++ b/pkg/procrunner/procrunner.go @@ -11,7 +11,6 @@ import ( "sync/atomic" "github.com/rs/zerolog/log" - "github.com/stumble/v8runner/pkg/types" ) @@ -47,7 +46,13 @@ type ProcRunner struct { func NewProcRunner(fileName string, maxHeapSizeMB uint) (*ProcRunner, error) { // Create the command // Should be safe to pass these parameters because they are not user input. - cmd := exec.Command("v8runner", "--file", fileName, "--max-heap", fmt.Sprintf("%d", maxHeapSizeMB)) //nolint:gosec + cmd := exec.Command( + "v8runner", + "--file", + fileName, + "--max-heap", + fmt.Sprintf("%d", maxHeapSizeMB), + ) //nolint:gosec // Set up the stdin, stdout, stderr stdin, err := cmd.StdinPipe() diff --git a/pkg/runner/libs.go b/pkg/runner/libs.go index 73df208..09a17bc 100644 --- a/pkg/runner/libs.go +++ b/pkg/runner/libs.go @@ -2,7 +2,6 @@ package runner import ( v8 "github.com/stumble/v8go" - "github.com/stumble/v8runner/pkg/types" ) diff --git a/pkg/runner/reader_runner.go b/pkg/runner/reader_runner.go index 93ebe73..7cb9465 100644 --- a/pkg/runner/reader_runner.go +++ b/pkg/runner/reader_runner.go @@ -18,7 +18,12 @@ type ReaderRunner struct { } // NewReaderRunner creates a new ReaderRunner that reads from input and writes to output. -func NewReaderRunner(input io.Reader, output io.Writer, fileName string, maxHeapSizeMB uint) (*ReaderRunner, error) { +func NewReaderRunner( + input io.Reader, + output io.Writer, + fileName string, + maxHeapSizeMB uint, +) (*ReaderRunner, error) { return &ReaderRunner{ FileName: fileName, MaxHeapSizeMB: maxHeapSizeMB, diff --git a/pkg/runner/reader_runner_test.go b/pkg/runner/reader_runner_test.go index e5924e5..e002c5f 100644 --- a/pkg/runner/reader_runner_test.go +++ b/pkg/runner/reader_runner_test.go @@ -9,7 +9,6 @@ import ( "testing" "github.com/stretchr/testify/suite" - "github.com/stumble/v8runner/pkg/types" ) diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index f782f99..651b9e6 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -8,9 +8,7 @@ import ( v8 "github.com/stumble/v8go" ) -var ( - ErrorTimeout = fmt.Errorf("timeout") -) +var ErrorTimeout = fmt.Errorf("timeout") type Option interface { Apply() error From 10e34b4d6cd74427a073a3140dad1e1dcb9554e6 Mon Sep 17 00:00:00 2001 From: tobin Date: Thu, 6 Nov 2025 15:37:27 +0800 Subject: [PATCH 4/4] fix lint --- pkg/procrunner/procrunner.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/procrunner/procrunner.go b/pkg/procrunner/procrunner.go index e26a901..9769edd 100644 --- a/pkg/procrunner/procrunner.go +++ b/pkg/procrunner/procrunner.go @@ -46,13 +46,14 @@ type ProcRunner struct { func NewProcRunner(fileName string, maxHeapSizeMB uint) (*ProcRunner, error) { // Create the command // Should be safe to pass these parameters because they are not user input. + //nolint:gosec // G204: Parameters are controlled and validated cmd := exec.Command( "v8runner", "--file", fileName, "--max-heap", fmt.Sprintf("%d", maxHeapSizeMB), - ) //nolint:gosec + ) // Set up the stdin, stdout, stderr stdin, err := cmd.StdinPipe()