script

package
v1.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 20, 2026 License: Apache-2.0 Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package script runs a scenario's JavaScript steps with goja. A script sees the virtual user's variables as `vars` (and may set new ones), the environment as `env`, its feeder rows as `data`, and `vu` and `iteration`; `fail(message)` fails the iteration. Scripts have no network, file or timer access, and each run is bounded by Timeout.

Index

Constants

View Source
const Timeout = time.Second

Timeout bounds one run of a script.

Variables

This section is empty.

Functions

This section is empty.

Types

type Failure

type Failure struct{ Message string }

Failure is a script calling fail(message).

func (*Failure) Error

func (f *Failure) Error() string

type Input

type Input struct {
	Vars      map[string]any
	Env       map[string]string
	Data      map[string]any
	VU        int64
	Iteration int64
	// Log receives console.log output; nil discards it.
	Log func(string)
}

Input is what a script sees.

type Program

type Program struct {

	// Source is the script as written, for error messages.
	Source string
	// contains filtered or unexported fields
}

Program is a compiled script.

func Compile

func Compile(name, code string) (*Program, error)

Compile parses code once, ahead of the run. The body runs as a function in strict mode, so `return` ends it early.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner runs scripts for one virtual user. It is not safe for concurrent use; give each virtual user its own.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, p *Program, in Input) (map[string]any, error)

Run executes p and returns the variables afterwards: in.Vars with the script's changes. in.Vars itself is not modified.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL