config

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinLatencyProfiles added in v1.0.0

func BuiltinLatencyProfiles() map[string]LatencyProfile

func ValidateLatencyProfile added in v1.0.0

func ValidateLatencyProfile(name string, profile LatencyProfile) []string

Types

type Config

type Config struct {
	CORS                  bool                      `yaml:"cors,omitempty"`
	Proxy                 string                    `yaml:"proxy,omitempty"`
	LatencyProfile        string                    `yaml:"latency_profile,omitempty"`         // default named latency profile for routes
	LatencyProfiles       map[string]LatencyProfile `yaml:"latency_profiles,omitempty"`        // custom named latency profiles
	OpenAPI               string                    `yaml:"openapi,omitempty"`                 // path to OpenAPI spec for request validation
	OpenAPIStrict         bool                      `yaml:"openapi_strict,omitempty"`          // return 400 on validation failures instead of warning
	OpenAPIStrictResponse bool                      `yaml:"openapi_strict_response,omitempty"` // return 500 when mock response violates schema
	Include               []string                  `yaml:"include,omitempty"`                 // glob patterns of additional config files to merge
	Routes                []Route                   `yaml:"routes"`
	Scenarios             map[string]Scenario       `yaml:"scenarios,omitempty"`
	Stores                map[string]StoreConfig    `yaml:"stores,omitempty"`
}

func Load

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

func LoadBytes added in v1.0.0

func LoadBytes(data []byte) (*Config, error)

type GraphQLMatch added in v0.5.0

type GraphQLMatch struct {
	Operation string            `yaml:"operation,omitempty"` // operationName regex/exact
	Variables map[string]string `yaml:"variables,omitempty"` // variable key → regex/exact
}

GraphQLMatch selects a match entry by GraphQL operation name and/or variables.

type LatencyProfile added in v1.0.0

type LatencyProfile struct {
	Delay    int `yaml:"delay,omitempty"`     // fixed response delay in ms
	DelayMin int `yaml:"delay_min,omitempty"` // min random delay in ms
	DelayMax int `yaml:"delay_max,omitempty"` // max random delay in ms
}

func ResolveLatencyProfile added in v1.0.0

func ResolveLatencyProfile(cfg *Config, name string) (LatencyProfile, bool)

type Route

type Route struct {
	Path           string            `yaml:"path"`
	Method         string            `yaml:"method"`
	Status         int               `yaml:"status,omitempty"`
	Delay          int               `yaml:"delay,omitempty"`           // milliseconds
	LatencyProfile string            `yaml:"latency_profile,omitempty"` // named latency profile for this route
	Headers        map[string]string `yaml:"headers,omitempty"`
	ContentType    string            `yaml:"content_type,omitempty"`
	Response       any               `yaml:"response,omitempty"`
	Mode           string            `yaml:"mode,omitempty"` // "sequential" (default) or "random"
	Responses      []RouteResponse   `yaml:"responses,omitempty"`
	Timeline       []RouteResponse   `yaml:"timeline,omitempty"`
	Match          []RouteMatch      `yaml:"match,omitempty"`
	RateLimit      int               `yaml:"rate_limit,omitempty"`      // max requests allowed
	RateReset      int               `yaml:"rate_reset,omitempty"`      // seconds until count resets
	State          string            `yaml:"state,omitempty"`           // required server state to match
	SetState       *string           `yaml:"set_state,omitempty"`       // state to set after responding
	Vars           map[string]string `yaml:"vars,omitempty"`            // require these vars to match
	SetVars        map[string]string `yaml:"set_vars,omitempty"`        // set these vars after responding
	Webhook        *Webhook          `yaml:"webhook,omitempty"`         // outgoing callback after responding
	File           string            `yaml:"file,omitempty"`            // path to response file (.json/.yaml/.yml)
	ErrorRate      float64           `yaml:"error_rate,omitempty"`      // 0.0-1.0 probability of injecting an error
	ErrorStatus    int               `yaml:"error_status,omitempty"`    // status code for injected error (default 503)
	Fault          string            `yaml:"fault,omitempty"`           // built-in fault profile to inject
	DelayMin       int               `yaml:"delay_min,omitempty"`       // min random delay in ms (used with delay_max)
	DelayMax       int               `yaml:"delay_max,omitempty"`       // max random delay in ms
	OnCall         int               `yaml:"on_call,omitempty"`         // match only on this call number (1-based)
	Script         string            `yaml:"script,omitempty"`          // Go template producing the response body
	Proxy          string            `yaml:"proxy,omitempty"`           // forward this route to a real backend
	Redirect       string            `yaml:"redirect,omitempty"`        // redirect to this URL/path (default status 302)
	RedirectStatus int               `yaml:"redirect_status,omitempty"` // override redirect status code (301/302/303/307/308)
	StorePush      string            `yaml:"store_push,omitempty"`      // push request body into named store → 201
	StoreList      string            `yaml:"store_list,omitempty"`      // list all items in named store → 200
	StoreGet       string            `yaml:"store_get,omitempty"`       // get item by store_key param → 200/404
	StorePut       string            `yaml:"store_put,omitempty"`       // replace/upsert item by store_key param → 200
	StorePatch     string            `yaml:"store_patch,omitempty"`     // merge into item by store_key param → 200/404
	StoreDelete    string            `yaml:"store_delete,omitempty"`    // delete item by store_key param → 204/404
	StoreClear     string            `yaml:"store_clear,omitempty"`     // clear all items in named store → 204
	StoreKey       string            `yaml:"store_key,omitempty"`       // path param used as item ID (default: "id")
	Stream         bool              `yaml:"stream,omitempty"`          // respond with a Server-Sent Events stream
	Events         []StreamEvent     `yaml:"events,omitempty"`          // SSE events to emit (requires stream: true)
	StreamRepeat   bool              `yaml:"stream_repeat,omitempty"`   // loop events until client disconnects
	SetCookies     []SetCookie       `yaml:"set_cookies,omitempty"`     // cookies to set in the response
	Priority       int               `yaml:"priority,omitempty"`        // higher = matched first among same (method, path) entries
	Times          int               `yaml:"times,omitempty"`           // max times this route matches (0 = unlimited)
}

type RouteMatch added in v0.3.0

type RouteMatch struct {
	Query           map[string]string `yaml:"query,omitempty"`
	Body            map[string]any    `yaml:"body,omitempty"`
	Headers         map[string]string `yaml:"headers,omitempty"`
	BodyPath        map[string]string `yaml:"body_path,omitempty"` // dot-notation path → regex pattern
	Status          int               `yaml:"status,omitempty"`
	ContentType     string            `yaml:"content_type,omitempty"`
	Response        any               `yaml:"response,omitempty"`
	File            string            `yaml:"file,omitempty"`
	Script          string            `yaml:"script,omitempty"`           // Go template producing the response body
	Form            map[string]string `yaml:"form,omitempty"`             // match application/x-www-form-urlencoded fields (regex)
	GraphQL         *GraphQLMatch     `yaml:"graphql,omitempty"`          // match GraphQL operationName / variables
	Cookies         map[string]string `yaml:"cookies,omitempty"`          // match cookie name → regex/exact
	BodySchema      map[string]any    `yaml:"body_schema,omitempty"`      // JSON Schema the request body must conform to
	SetState        *string           `yaml:"set_state,omitempty"`        // transition server state after this match
	SetVars         map[string]string `yaml:"set_vars,omitempty"`         // set vars after this match
	ResponseHeaders map[string]string `yaml:"response_headers,omitempty"` // response headers to set/override when this match fires
	Delay           int               `yaml:"delay,omitempty"`            // additional delay (ms) applied after this match fires
	Fault           string            `yaml:"fault,omitempty"`            // built-in fault profile to inject
}

type RouteResponse added in v0.2.0

type RouteResponse struct {
	Status      int    `yaml:"status,omitempty"`
	ContentType string `yaml:"content_type,omitempty"`
	Response    any    `yaml:"response,omitempty"`
	File        string `yaml:"file,omitempty"`
	OnCall      int    `yaml:"on_call,omitempty"` // match only on this call number (1-based)
	Script      string `yaml:"script,omitempty"`  // Go template producing the response body
	Fault       string `yaml:"fault,omitempty"`   // built-in fault profile to inject
}

type Scenario added in v1.0.0

type Scenario struct {
	State  string                      `yaml:"state,omitempty"`  // server state to set when scenario is applied
	Vars   map[string]string           `yaml:"vars,omitempty"`   // vars to replace when scenario is applied
	Stores map[string][]map[string]any `yaml:"stores,omitempty"` // store collections to replace when scenario is applied
}

type SetCookie added in v0.5.0

type SetCookie struct {
	Name     string `yaml:"name"`
	Value    string `yaml:"value"`
	Path     string `yaml:"path,omitempty"`
	Domain   string `yaml:"domain,omitempty"`
	MaxAge   int    `yaml:"max_age,omitempty"` // seconds; 0 = session cookie
	HTTPOnly bool   `yaml:"http_only,omitempty"`
	Secure   bool   `yaml:"secure,omitempty"`
	SameSite string `yaml:"same_site,omitempty"` // Strict, Lax, None
}

SetCookie describes a cookie to set in the response.

type StoreConfig added in v1.0.0

type StoreConfig struct {
	Seed []map[string]any `yaml:"seed,omitempty"` // initial items for the named CRUD store
}

type StreamEvent added in v0.5.0

type StreamEvent struct {
	Data  any    `yaml:"data,omitempty"`  // event payload (string or JSON-serialisable)
	Event string `yaml:"event,omitempty"` // SSE event type name (default: omitted → "message")
	ID    string `yaml:"id,omitempty"`    // SSE event ID
	Delay int    `yaml:"delay,omitempty"` // milliseconds to wait before sending this event
}

StreamEvent is a single SSE event emitted by a streaming route.

type Webhook added in v0.4.0

type Webhook struct {
	URL     string            `yaml:"url"`
	Method  string            `yaml:"method,omitempty"` // default: POST
	Body    any               `yaml:"body,omitempty"`
	Headers map[string]string `yaml:"headers,omitempty"`
	Delay   int               `yaml:"delay,omitempty"` // milliseconds before sending
}

Jump to

Keyboard shortcuts

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