file-patch-sink

command
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package main demonstrates file.DrainPatchAdapter and file.DrainPatchEncodedAdapter: ports.SinkPort-bound sink adapters that apply each stream item as a PARTIAL update to an existing typed file, instead of the whole-file overwrite file.DrainWriteFileAdapter performs.

Scenario: a service config file on disk receives a stream of incremental updates (e.g. from an admin API or config-management pipeline) and must be patched in place — untouched fields must survive.

Two scenes:

  • DrainPatchAdapter: untyped map[string]any patches (JSON Merge Patch semantics via ports.File.Patch) — a SinkPort[map[string]any].
  • DrainPatchEncodedAdapter: a typed patch struct via a dedicated patch codec (via ports.PatchEncoded) — a SinkPort[ConfigPatch]; fields in the patch codec but NOT in the file's own codec are still persisted.

Both adapters stay handle-first (a hand-built ports.File[T] passed directly, not declared via ports.FilePattern) because the patch item's type is deliberately different from the file's own whole-record type — the same reason file.ReadEachAdapter stays handle-first for its independent content type.

Run with: go run ./examples/file-patch-sink

Jump to

Keyboard shortcuts

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