[READ-ONLY] Mirror of https://github.com/NathanBeddoeWebDev/odin_config.
README.md

odin_config #

config owns immutable configuration snapshots. The format loaders are independent, importable packages:

  • path/to/odin_config/json (config_json) parses or loads JSON.
  • path/to/odin_config/ini (config_ini) parses or loads INI.
  • path/to/odin_config/toml (config_toml) strictly parses or loads TOML 1.1.
  • path/to/odin_config/auto (config_auto) selects JSON, INI, or TOML from a path extension.
import config "path/to/odin_config"
import config_auto "path/to/odin_config/auto"

document := config.New()
defer config.Destroy(&document)

if err := config_auto.Load(document, "settings.json"); err != nil {
	// The previously loaded snapshot is still available.
	return
}

host, found := config.Get_Key(config.Root(document), "host")
if found {
	value, ok := config.As_String(host)
	// use value when ok
}

For configuration data already in memory, call config_json.Parse or config_ini.Parse directly, or use config_auto.Load_String with a filename hint. TOML strings, integers, floats, booleans, arrays, and tables map to the existing config value model. TOML temporal values are rejected explicitly until that model gains temporal value kinds.

Development #

odin_toml is a pinned Git submodule at external/odin_toml. Initialize it when cloning:

git clone --recurse-submodules git@github.com:NathanBeddoeWebDev/odin_config.git

Odin does not persist project collections, so commands that build a package which imports TOML must define the external collection:

odin test toml -collection:external=external
odin test auto -collection:external=external
odin test tests -collection:external=external

Ownership and lifetime #

  • New returns an owning Document handle. Do not copy a live handle; call Destroy exactly once on the handle returned by New.
  • Root, Get_Key, and Get_Index return opaque, read-only borrowed Value views. Inspect them with Kind, As_String, As_Integer, As_Float, and As_Boolean.
  • Borrowed values become invalid after a successful load or Clear; accessors then report an invalid value. Failed loads preserve the current snapshot and its borrowed values. Values must not be accessed after Destroy.
  • Successful loads are transactional: parsing and conversion occur in a candidate snapshot, which replaces the current snapshot only after success. Concurrent reads and mutation require external synchronization.