MCPcopy Create free account
hub / github.com/cozystack/talm / encodeYAMLNodeIndented

Function encodeYAMLNodeIndented

pkg/engine/engine.go:2049–2062  ·  view source on GitHub ↗

encodeYAMLNodeIndented writes node to w as 2-space-indented YAML and returns wrapped errors for both the encode and close phases. Hoisted out of applyPatchesAndRenderConfig so the close-error wrap is unit-testable via a fault-injecting writer; sister sites at engine.go:585 and :765 use the same enco

(w io.Writer, node *yaml.Node)

Source from the content-addressed store, hash-verified

2047// is unit-testable via a fault-injecting writer; sister sites at
2048// engine.go:585 and :765 use the same encode+close idiom inline.
2049func encodeYAMLNodeIndented(w io.Writer, node *yaml.Node) error {
2050 enc := yaml.NewEncoder(w)
2051 enc.SetIndent(2)
2052
2053 if err := enc.Encode(node); err != nil {
2054 return errors.Wrap(err, "encoding target config")
2055 }
2056
2057 if err := enc.Close(); err != nil {
2058 return errors.Wrap(err, "closing target config encoder")
2059 }
2060
2061 return nil
2062}
2063
2064func readUnexportedField(field reflect.Value) any {
2065 return reflect.NewAt(field.Type(), unsafe.Pointer(field.UnsafeAddr())).Elem().Interface()

Calls

no outgoing calls