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).
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.).
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. |