Export an F-Mesh mesh as YAML: its structure, or its state in one cycle of a run. Use it for config-style review, diffs in pull requests, or snapshots in tests.
New() returns an Exporter. It implements this module's
export.Exporter, like every format in this
module. It has no options and no state: reuse one value for many meshes.
The documents are exactly the ones the json exporter writes, in YAML syntax. Both
packages share the types: yaml.Mesh is json.Mesh.
go get github.com/hovsep/fmesh-export/yamlimport "github.com/hovsep/fmesh-export/yaml"
data, err := yaml.New().Export(fm)name: pricing
description: computes prices
meta:
env: prod
components:
- name: dst
inputs:
- name: in
description: prices in
outputs: []
- name: src
description: emits prices
meta:
weight: 2
inputs:
- name: start
outputs:
- name: out
pipes:
- from:
component: src
port: out
to:
component: dst
port: in- Components and ports are in name order, metadata keys sorted. Pipes are grouped by source port, in the same order, and each port's pipes are in wiring order. The same mesh always exports the same bytes.
descriptionandmetaare left out when empty.components,inputs,outputsandpipesare always present.- Names are quoted when YAML needs it (
a: b,#x,yes,null, ...), so they read back as written. - Unmarshal into
yaml.Meshto read it back, for example withgo.yaml.in/yaml/v3. - A float metadata value with no fraction is written as an integer (
2.0→2), so it reads back as anintintomap[string]any.
ri, err := fm.Run(ctx)
for _, c := range ri.Cycles.All() {
frame, err := yaml.New().ExportCycle(fm, c)
}The document is a yaml.Cycle: the cycle number, the mesh structure, and one results entry
per component, in name order:
results:
- component: dst
code: Finished with error
activated: true
errors:
- 'component returned an error: boom'
- component: src
code: No input
activated: false- A component with no result in the cycle had no input: its code is
No input. - A nil mesh returns
export.ErrNilMesh, and a nil cycleexport.ErrNilCycle. - To export each cycle while the mesh runs, call
ExportCyclefrom anAfterCyclehook.