Documentation
¶
Overview ¶
Package value merges codec value trees with configurable array semantics.
Merge overlays one decoded value tree onto another: objects merge recursively and, by default, later scalars win. MergeWith takes an ArrayStrategy to choose how arrays combine (replace, concatenate, …) per use case such as layered configuration.
Package value provides operations over the canonical codec value tree.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Merge ¶
Merge deep-merges overlay onto base, replacing arrays wholesale.
Objects (map[string]any) merge recursively; on a key collision the overlay value wins (last-wins scalars). Every array ([]any) is replaced by the overlay. Use MergeWith to concatenate selected arrays instead. Neither input is mutated.
func MergeWith ¶
func MergeWith(base, overlay any, arrayStrategy func(key string) ArrayStrategy) any
MergeWith deep-merges overlay onto base, choosing an array strategy per key.
Objects merge recursively; on a key collision the overlay value wins. When both sides hold an array at the same key, arrayStrategy is consulted with that key to decide Replace vs Concat. A nil arrayStrategy is treated as always Replace, matching Merge. Type mismatches (for example object vs scalar) resolve to the overlay. Neither input is mutated.
Types ¶
type ArrayStrategy ¶
type ArrayStrategy int
ArrayStrategy chooses how two arrays found at the same key combine during a merge. The strategy is selected per key by the caller (see MergeWith); the merge mechanism itself is policy-free and does not know what any key "means".
const ( // Replace makes the overlay array replace the base array wholesale (last-wins). It is the default. Replace ArrayStrategy = iota // Concat appends the overlay array to the base array (concatenation). Concat )