Documentation
¶
Overview ¶
Package transform provides composable, post-merge / pre-decode transformations on the merged configuration tree.
FastConf's reload pipeline is conceptually:
discover → decode → merge/patch → [TRANSFORMERS] → decodeInto(*T)
→ validate → publish
A Transformer is a pure function `func(map[string]any) error` that may mutate the in-place merged map before it is decoded into the user's strongly-typed struct. Built-in transformers cover the most common cases (defaults, env interpolation, key aliasing, deletion). Users can also write their own.
Transformers run in declaration order and are wired via `fastconf.WithTransformers(...)`. Failures abort the reload and the previously committed state is preserved (same guarantee as every other stage).
Design notes:
- Transformers operate on `map[string]any` rather than `*T` so they remain decoupled from the user type and can be reused across multiple Manager[T] instances.
- Path syntax used by helpers below is dotted: "a.b.c". Numeric indices into slices are NOT supported (config trees are usually small maps; complex array surgery belongs in RFC 6902 patches).
- All helpers tolerate a nil root map (treated as empty); they never panic on missing intermediate nodes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTransform = errors.New("fastconf/internal/transform")
ErrTransform is returned wrapped by built-in transformers on failure.
Functions ¶
Types ¶
type Transformer ¶
Transformer mutates the merged configuration tree. Returning an error aborts the reload. Implementations MUST be safe to call concurrently with reads of unrelated Manager instances but are guaranteed to be invoked serially within a single reload.
func Aliases ¶
func Aliases(mapping map[string]string) Transformer
Aliases returns a Transformer that rewrites legacy keys to their new home. If the target path already has a value the new world wins and the alias is dropped.
func Defaults ¶
func Defaults(values map[string]any) Transformer
Defaults returns a Transformer that recursively merges the supplied values into the tree, only filling keys that are missing.
func DeletePaths ¶
func DeletePaths(paths ...string) Transformer
DeletePaths returns a Transformer that removes the specified dotted-path keys from the tree. Missing paths are silently ignored.
func EnvSubst ¶
func EnvSubst() Transformer
EnvSubst returns a Transformer that walks every string value in the tree and substitutes occurrences of ${VAR} or ${VAR:-default}.
func EnvSubstWith ¶
func EnvSubstWith(lookup func(string) string) Transformer
EnvSubstWith is like EnvSubst but reads variables through the supplied lookup function.
func SetIfAbsent ¶
func SetIfAbsent(path string, value any) Transformer
SetIfAbsent sets a single dotted-path key only when it has no value.
type TransformerFunc ¶
TransformerFunc adapts a plain function to the Transformer interface.
func (TransformerFunc) Name ¶
func (t TransformerFunc) Name() string