Documentation
¶
Overview ¶
Package decoder 把不同编码(yaml/json/...)的字节流解码为统一的 map[string]any 中间表示。该中间表示只在 reload 流水线内部存在, 不会出现在公开 API 上。
解码器通过进程内 registry 注册(见 registry.go)。内置 yaml/yml/json 在 init 时注册;外部 codec(toml/hcl/json5/...)可通过 fastconf.RegisterCodec 在仓库外注入。
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownCodec = errors.New("decoder: unknown codec")
ErrUnknownCodec 表示不识别的 codec 名。
Functions ¶
func CodecFromExt ¶
CodecFromExt infers a codec name from a file extension (with or without the leading dot). Returns empty string when the extension is unrecognised. Queries only codecs registered via RegisterCodec/RegisterCodecExt.
func DecodeAny ¶
DecodeAny decodes data as either an object or an array (used for RFC 6902 patch layers whose top-level node is an array).
Returns either map[string]any or []any. Returns nil on empty input.
func Lookup ¶
Lookup returns the codec for name (case-insensitive) along with an "exists" flag. Used by tests to assert registration ordering.
func LookupExt ¶
LookupExt returns the codec name for a given extension, or "" if the extension is unknown.
func Register ¶
Register installs c under the given name (case-insensitive). It is safe for concurrent use. Registering nil panics; that signals a bug at init time and we prefer to fail loudly rather than silently dropping the codec on first use. Re-registering an existing name overwrites it, which makes test helpers and feature toggles ergonomic.
func RegisterExt ¶
func RegisterExt(ext, codec string)
RegisterExt maps a file extension (with or without leading dot, case insensitive) to a codec name. It does NOT register the codec itself — the caller should also call Register if the codec is custom.