inputs

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package inputs gives scenario scripts the data and settings they read from outside the script (FR-CLI-17): data files whose rows feed virtual users, and environment variables the run exposes by name.

A script can only read an environment variable the run named with -env or -secret-env. Nothing else in the process environment is reachable through the `env` global, so a scenario written by someone else (or by an agent) cannot sweep up unrelated secrets. A value named with -secret-env is registered with internal/secrets, which keeps it out of the report, the JSON output, the audit record and logs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckColumns added in v0.9.0

func CheckColumns(slots []Slot, sets map[string]*Set) error

CheckColumns reports a column that is not in its data set. The message names the file and the column, not a cell.

func ParseData

func ParseData(specs []string) (map[string]*Set, error)

ParseData loads each -data value. A value is a path, or name=path. A bare path is named after the file, without its extension, so users.csv is `data.users`. Names must be usable as an identifier in a script.

func ResolveEnv

func ResolveEnv(plain, secret []string) (map[string]string, error)

ResolveEnv reads the named environment variables. Names in secret are also registered as secrets. A name may be listed in both; it is then a secret. Each name may be a comma-separated list. A variable that is not set is an error, so a typo shows before any load is sent.

Types

type Inputs

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

Inputs implements netapi.Inputs.

func New

func New(env map[string]string, sets map[string]*Set) *Inputs

New returns Inputs for the given variables and data files, or nil when there are none, which is how the scripting runtimes know to expose nothing.

func (*Inputs) Dataset

func (in *Inputs) Dataset(name string) (netapi.Dataset, bool)

Dataset returns the data file named name.

func (*Inputs) DatasetNames

func (in *Inputs) DatasetNames() []string

DatasetNames lists the data file names, sorted.

func (*Inputs) Env

func (in *Inputs) Env(name string) (string, bool)

Env returns an exposed variable.

func (*Inputs) EnvNames

func (in *Inputs) EnvNames() []string

EnvNames lists the exposed variable names, sorted.

type Set

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

Set is one data file's rows.

func LoadSet

func LoadSet(name, path string) (*Set, error)

LoadSet reads a CSV file (a header row, then one row per line) or a JSON file (an array of objects). The extension picks the format.

func (*Set) FileName added in v0.9.0

func (s *Set) FileName() string

FileName is the base name of that file.

func (*Set) First added in v0.9.0

func (s *Set) First() map[string]any

First is a copy of the first row. It does not move the next-row counter.

func (*Set) HasColumn added in v0.9.0

func (s *Set) HasColumn(column string) bool

HasColumn reports whether every row has column.

func (*Set) Len

func (s *Set) Len() int

Len is the number of rows.

func (*Set) Name added in v0.9.0

func (s *Set) Name() string

Name is the data set name, the same name a script uses.

func (*Set) Next

func (s *Set) Next() map[string]any

Next returns the next row in file order, shared by every caller, and starts again from the first row after the last.

func (*Set) Path added in v0.9.0

func (s *Set) Path() string

Path is the file this set was loaded from.

func (*Set) Random

func (s *Set) Random() map[string]any

Random returns any row.

type Slot added in v0.9.0

type Slot struct {
	Set    string
	Column string
	// contains filtered or unexported fields
}

Slot is one placeholder in a template.

type Template added in v0.9.0

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

Template is a string split once into literal parts and slots. Filling a template that has no slots returns the original string.

func Parse added in v0.9.0

func Parse(s string, asArgs bool) (Template, error)

Parse splits s into literals and placeholders. asArgs is true for an -opt args value: a placeholder with no suffix is replaced by the JSON form of the cell. Everywhere else the cell is inserted as plain text.

func (Template) Fill added in v0.9.0

func (t Template) Fill(rows map[string]map[string]any) (string, error)

Fill replaces each placeholder from rows, which maps a data set name to the one row this call drew. A template with no slots returns the original string and does not allocate.

func (Template) HasSlots added in v0.9.0

func (t Template) HasSlots() bool

HasSlots reports whether Fill will read a row.

func (Template) Slots added in v0.9.0

func (t Template) Slots() []Slot

Slots lists the placeholders, in order.

Jump to

Keyboard shortcuts

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