Skip to content

Stumble/v8runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

V8 runner

Run javascript code in a separated process.

Runner binary

Install the runner binary to $PATH. (Assuming your GOPATH is added to PATH).

make install-v8runner

Caller

NOTE: Caller must have v8runner binary installed in $PATH.

Dockerfile example:

FROM golang:1.21 AS build

....
RUN go install github.com/stumble/v8runner/cmd/v8runner@v0.0.4
....

FROM gcr.io/distroless/cc-debian12

....
COPY --from=build /go/bin/v8runner /usr/local/bin/
...

Example usecase and code:

$ go run cmd/example/runcode/runcode.go
undefined
{"a":1,"b":2}

Code:

package main

import (
	"context"
	"fmt"
	"github.com/stumble/v8runner/pkg/procrunner"
)

func main() {
	const maxHeapSizeMB = 16
	const jsFileName = "expression.js"
	runner, err := procrunner.NewProcRunner(jsFileName, maxHeapSizeMB)
	if err != nil {
		panic(err)
	}
	defer runner.Close()

	res, err := runner.RunCodeJSON(context.Background(), "const f = (data) => { return {a: data.X, b: data.Y} };")
	if err != nil {
		panic(err)
	}
	fmt.Println(res)
	res, err = runner.RunCodeJSON(context.Background(), "f({X: 1, Y: 2});")
	if err != nil {
		panic(err)
	}
	fmt.Println(res)
}

Server

TBD.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •