go.bigb.es/auxilia

v0.6.0
Doc Versions Source

Documentation

Package flowspec turns a legatus Flow into a single declarative table instead of imperative builder code. A Spec is a list of Rows; each Row carries the conditionality that consumers otherwise hand-roll as control flow:

  • Gate — a static feature gate (the `if cfg.X.Enabled` around a block).
  • Over — a fan-out list (the `for _, e := range cfg.Exits` loop).
  • When — a per-host apply-time gate (steps.When), evaluated against the host.
  • Make — the step factory for one item.

Spec implements legatus.FlowSource, so a Spec is handed to Runner.Run exactly where a static Flow would be. Resolve lowers the table to a Flow once, before any host fan-out, which is why Gate/Over are host-independent and only When sees the host.

Types

T type Row

src
type Row struct {
	Gate func() bool
	Over func() []string
	When func(*legatus.FlowCtx) bool
	Make func(item string) ([]legatus.Step, error)
}

Row is one entry in a Spec. Every column is optional except Make:

  • Gate nil — the row is always included; false drops it (Over/Make unrun).
  • Over nil — a single pass with item == ""; otherwise one pass per element.
  • When nil — the emitted steps are unconditional; otherwise each is wrapped in steps.When{Cond: When}.

T type Spec

src
type Spec struct {
	Name string
	Rows []Row
}

Spec is a named, ordered table of Rows that resolves to a legatus.Flow.

m func (Spec) Resolve

src
func (s Spec) Resolve() (legatus.Flow, error)

Resolve lowers the table to a Flow, walking rows in declaration order: a row whose Gate is false contributes nothing; otherwise Make runs once per Over item (or once with ""), and each produced step is wrapped in steps.When when the row has a When gate. The first Make error aborts, returning Flow{Name} (no steps) plus the error so the Runner can name the failed flow.

Source Files