Help us shape the future of Go! Take the 2026 Go Developer Survey

catalog

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package catalog is the list of requests DriftGate sends: one entry is one request, and variants of a route are separate entries with their own ID.

Index

Constants

View Source
const MaxRepeat = 10000

MaxRepeat bounds repeat: a catalog entry is a check, not a load test.

View Source
const Version = 1

Variables

This section is empty.

Functions

func CheckPath

func CheckPath(path string) error

CheckPath refuses a request or route path that does not start with "/". The path is appended to the base URL, so "@host/x" or ".example.com/x" would send the request, with the identity's token, to another host.

func MutatesFor

func MutatesFor(method string) *bool

MutatesFor is the mutates field a new entry gets from its method: true for one that is not safe, unset otherwise.

func SafeMethod

func SafeMethod(method string) bool

SafeMethod reports a method that only reads: GET, HEAD, OPTIONS, or none (which is sent as GET).

Types

type Catalog

type Catalog struct {
	Version   int        `json:"version"`
	Requests  []Request  `json:"requests"`
	Sequences []Sequence `json:"sequences,omitempty"`
}

Catalog is driftgate/catalog.json.

func Load

func Load(path string) (*Catalog, error)

Load reads and validates a catalog.

func (*Catalog) Save

func (c *Catalog) Save(path string) error

Save writes the catalog with stable formatting.

func (*Catalog) Validate

func (c *Catalog) Validate() error

Validate checks IDs, methods, storage and levels. A method is written in upper case, as servers and the safe methods are: "post" becomes POST.

type File

type File struct {
	Field     string `json:"field"`
	Path      string `json:"path,omitempty"`
	Ref       string `json:"ref,omitempty"` // keyed hash of the content (as a private body is named); a changed file is a configuration change
	Synthetic string `json:"synthetic,omitempty"`
	Name      string `json:"name,omitempty"` // file name sent; default the base name of path, or upload.<ext>
	Type      string `json:"type,omitempty"` // content type of the part; default from the kind or the extension
}

File is one file of a multipart body: a real file from the uploads folder outside the repository, named by its path relative to that folder and checked by Ref, or a synthetic file of a kind (upload.Kinds). The content never enters the catalog.

type From

type From struct {
	Request string `json:"request"`
	Path    string `json:"path"` // JSON path, e.g. $.entry.id or $.entries[0].id
}

From names a value in the body of another request's response.

type Multipart

type Multipart struct {
	Fields [][2]string `json:"fields,omitempty"`
	Files  []File      `json:"files,omitempty"`
}

Multipart is a multipart/form-data body: form fields in order, then files.

type Request

type Request struct {
	ID     string            `json:"id"`
	Target string            `json:"target,omitempty"` // the service, with several targets
	Method string            `json:"method"`
	Path   string            `json:"path"`
	Params map[string]string `json:"params,omitempty"`
	// ParamsFrom takes parameter values from the response of an earlier
	// request of the same capture.
	ParamsFrom map[string]From `json:"params_from,omitempty"`
	Headers    [][2]string     `json:"headers,omitempty"`
	Body       json.RawMessage `json:"body,omitempty"`
	Identity   string          `json:"identity,omitempty"`
	// Mutates says whether the request changes data; unset, a method other
	// than GET, HEAD and OPTIONS does (see Mutating). A search sent as POST
	// is written mutates: false.
	Mutates *bool   `json:"mutates,omitempty"`
	Storage string  `json:"storage"`
	Level   string  `json:"level,omitempty"`
	Observe bool    `json:"observe,omitempty"`
	Source  *Source `json:"source,omitempty"`
	// A multipart body with files, sending N times, a command step.
	Multipart    *Multipart `json:"multipart,omitempty"`
	Repeat       int        `json:"repeat,omitempty"`
	Command      []string   `json:"command,omitempty"`
	Output       bool       `json:"output,omitempty"`
	OutputIgnore []string   `json:"output_ignore,omitempty"`
}

Request is one catalog entry.

func (Request) IsCommand

func (r Request) IsCommand() bool

IsCommand reports an entry that runs a command instead of sending a request.

func (Request) Mutating

func (r Request) Mutating() bool

Mutating reports a request that changes data: mutates as written, else any method that is not safe. A request that changes data runs after a restore, one at a time, and needs a state with a restore command.

func (Request) MutatingByMethod

func (r Request) MutatingByMethod() bool

MutatingByMethod reports a request that changes data only because of its method: the catalog does not say mutates. A search sent as POST is one until it is written mutates: false.

func (Request) Sequential

func (r Request) Sequential() bool

Sequential reports an entry that runs one at a time after the read-only requests, like a request that changes data: a command, a request sent several times (its counters live in the state), or one that uploads a real file (its content may stay in the data, so every response after it until the next restore is stored as private, which only the sequential phase does).

func (Request) UsesFiles

func (r Request) UsesFiles() bool

UsesFiles reports an entry that sends a file from the uploads folder.

type Sequence

type Sequence struct {
	ID       string   `json:"id"`
	Restore  string   `json:"restore,omitempty"` // "before" or empty
	Requests []string `json:"requests"`
}

Sequence is a group of requests that run in order.

type Source

type Source struct {
	Route    string `json:"route,omitempty"`
	Template string `json:"template,omitempty"`
	Import   string `json:"import,omitempty"`
}

Source records where an entry came from.

Jump to

Keyboard shortcuts

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