Documentation
¶
Overview ¶
Package ktav is the Go binding for the Ktav configuration format.
The implementation loads a prebuilt `ktav_cabi` shared library via purego (no cgo required on the consumer side). On first call the library is downloaded from the matching GitHub Release and cached under the user cache directory; set $KTAV_LIB_PATH to point at a local build instead.
Type mapping ¶
Loads/Dumps convert between Ktav values and Go values as follows:
Ktav Go
─────────────── ───────────────────────────
null nil
true / false bool
:i <digits> int64 if it fits, else *big.Int
:f <number> float64
bare scalar string
[ ... ] []any
{ ... } map[string]any (key order not preserved)
Key order from the source is **not** preserved on either side: decode returns a plain `map[string]any`, and encode goes through `encoding/json`, which emits object keys in alphabetical order. If you need a fixed shape, use `LoadsInto` into a struct.
On encode, Go *big.Int always emits `:i`; Go int / int64 / uint64 emit `:i`; Go float64 emits `:f`; Go string emits a bare scalar. NaN / ±Inf are rejected. Top-level value must encode to a Ktav object (i.e. a map[string]any or struct) or a Ktav array (i.e. a []any or any other JSON-encodable slice). Top-level Arrays render as bare item-per-line — no surrounding `[...]` brackets, per spec § 5.0.1 (added in 0.1.1).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dumps ¶
Dumps renders a Go value as a Ktav document. The top-level must encode to a JSON object (map[string]any, struct, etc.) or a JSON array (a slice). Top-level Arrays render as bare item-per-line — no surrounding `[...]` brackets, per spec § 5.0.1 (added in 0.1.1).
func DumpsForceStrings ¶ added in v0.3.1
DumpsForceStrings renders a Go value as a Ktav document with **every scalar coerced to a String**: typed integers (`:i`), typed floats (`:f`), booleans, and null are flattened to their textual form via the raw-marker `::`. Compounds (Object / Array) preserve their structure; only leaf scalars are coerced.
The output round-trips back through `Loads` as the same set of String scalars — useful for environments or downstream consumers that don't understand the `:i` / `:f` typed markers, or for diffs where you want the textual form to be the canonical source of truth.
Top-level shape rules match `Dumps`: object or array.
func Loads ¶
Loads parses a Ktav document and returns its Go representation (see package doc for the mapping).
func LoadsInto ¶
LoadsInto parses a Ktav document and JSON-unmarshals the tagged intermediate into `target`. Handy for struct-typed configs:
var cfg MyConfig _ = ktav.LoadsInto(src, &cfg)
`:i` scalars become JSON numbers or JSON strings (if they exceed json.Number precision); `:f` scalars become JSON numbers. Custom types wanting bigint precision should unmarshal into a json.Number field.
func NativeVersion ¶
NativeVersion returns the version string baked into the loaded `ktav_cabi` shared library. Useful for diagnostics when a stale cache or KTAV_LIB_PATH points at an out-of-sync build.
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
End-to-end demo: parse a Ktav document into a typed struct, walk the dynamic shape, then build a fresh document in Go and render it back to Ktav text.
|
End-to-end demo: parse a Ktav document into a typed struct, walk the dynamic shape, then build a fresh document in Go and render it back to Ktav text. |
|
internal
|
|
|
native
Package native resolves and dynamically loads the `ktav_cabi` shared library via purego.
|
Package native resolves and dynamically loads the `ktav_cabi` shared library via purego. |