feed

package
v1.2.0 Latest Latest
Warning

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

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

Documentation

Overview

Package feed provides the test-data sources that are more than a file: rows of generated fake data and rows read from a database query.

Index

Constants

View Source
const MaxSQLRows = 1_000_000

MaxSQLRows bounds a SQL feeder: rows are held in memory for the run.

View Source
const MaxText = 64 << 20

MaxText bounds text(size): a generated payload is held in memory once per field and reused.

View Source
const SQLTimeout = time.Minute

SQLTimeout bounds the query.

Variables

View Source
var Drivers = map[string]string{"postgres": "pgx", "mysql": "mysql"}

Drivers maps the scenario's driver names to database/sql drivers.

View Source
var Kinds = []string{
	"name", "firstName", "lastName", "email", "username", "password", "phone", "uuid", "seq",
	"company", "street", "city", "country", "zip", "word", "sentence", "paragraph",
	"bool", "date", "datetime", "ipv4", "int(min,max)", "float(min,max)", "pick(a|b|c)", "text(size)",
}

Kinds lists the generator kinds, for help text and validation messages.

Functions

func Compile

func Compile(kind string) (func(g *Generator, n uint64, row map[string]any) any, error)

Compile parses one kind.

func Expand

func Expand(s string, env, secrets map[string]string) string

Expand replaces ${env.X} and ${secret.X} in s.

func SQLHost

func SQLHost(driver, dsn string) (string, error)

SQLHost returns the host:port a DSN connects to, so callers can vet it like any request host.

func SQLRows

func SQLRows(ctx context.Context, driver, dsn, query string, limit int) ([]any, error)

SQLRows runs query and returns each row as a map of column to value. Byte columns become strings. limit caps the rows (0 means MaxSQLRows).

Types

type Generator

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

Generator makes a fresh row of fake data each time it is asked. Values that must not collide (email, username, seq) include the worker's index, so rows never repeat within a run, even across workers.

func NewGenerator

func NewGenerator(spec map[string]string, index, count int) (*Generator, error)

NewGenerator compiles spec, a map of field name to kind, for worker index of count.

func (*Generator) Row

func (g *Generator) Row() map[string]any

Row returns a new row.

func (*Generator) SetAttempt

func (g *Generator) SetAttempt(a int)

SetAttempt marks a generator that takes over a lost worker's share (attempt 1, 2 ...), so its unique values differ from the lost worker's.

Jump to

Keyboard shortcuts

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