Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
Expand Down
145 changes: 68 additions & 77 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -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
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
5 changes: 4 additions & 1 deletion cmd/example/memtest/memtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/example/runcode/runcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 4 additions & 1 deletion cmd/example/runjsfile/runjsfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
module github.com/stumble/v8runner

go 1.21
go 1.24

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 (
github.com/davecgh/go-spew v1.1.1 // indirect
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
)
12 changes: 10 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
4 changes: 1 addition & 3 deletions pkg/procrunner/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions pkg/procrunner/procrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"sync/atomic"

"github.com/rs/zerolog/log"

"github.com/stumble/v8runner/pkg/types"
)

Expand Down Expand Up @@ -47,7 +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.
cmd := exec.Command("v8runner", "--file", fileName, "--max-heap", fmt.Sprintf("%d", maxHeapSizeMB)) //nolint:gosec
//nolint:gosec // G204: Parameters are controlled and validated
cmd := exec.Command(
"v8runner",
"--file",
fileName,
"--max-heap",
fmt.Sprintf("%d", maxHeapSizeMB),
)

// Set up the stdin, stdout, stderr
stdin, err := cmd.StdinPipe()
Expand Down Expand Up @@ -172,7 +178,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 {
Expand Down
3 changes: 1 addition & 2 deletions pkg/runner/libs.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package runner

import (
v8 "rogchap.com/v8go"

v8 "github.com/stumble/v8go"
"github.com/stumble/v8runner/pkg/types"
)

Expand Down
7 changes: 6 additions & 1 deletion pkg/runner/reader_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion pkg/runner/reader_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

"github.com/stretchr/testify/suite"

"github.com/stumble/v8runner/pkg/types"
)

Expand Down
6 changes: 2 additions & 4 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ import (
"fmt"
"strings"

v8 "rogchap.com/v8go"
v8 "github.com/stumble/v8go"
)

var (
ErrorTimeout = fmt.Errorf("timeout")
)
var ErrorTimeout = fmt.Errorf("timeout")

type Option interface {
Apply() error
Expand Down