01 / CONTROL
config
Parse a JSON or YAML config string into a ServiceConf: a strict derived FromJson path plus lenient ServiceConf::from_json / from_yaml loaders that fill omitted fields from the new() defaults, so a document may name only what it changes.
WHERE IT SITS
INTERFACE
struct ServiceConfstruct
fn ServiceConf::new( name~ : String = "app", host~ : String = "0.0.0.0", port~ : Int32 = port, timeout_ms~ : Int32 = 3000, log_level~ : @logx.LogLevel = Info) -> ServiceConffnBuild a config with sensible defaults (0.0.0.0:12000, 3s timeout, info).
extend ServiceConf with Eq::item
let port : Int32 = 12000letThe default port a moonzero service listens on. 12000 is the family's number, not 8888: every example, every document and every local run in this ecosystem points at the same place, and on a development machine 8888 is somebody else's already.
let rpc_port : Int32 = 12001letThe default port the zRPC server listens on. gRPC shares 12000 with HTTP wherever one listener carries both, but a moonzero process binds RestEngine and RpcServer separately — two listeners cannot hold one port — so the second takes the next number.
suberror RefuseditemA config-loading failure: malformed JSON or YAML, a non-mapping root, a field of the wrong type, a required field with no value, or a value outside its options=/range= constraint, with a human-readable reason.
fn ServiceConf::from_json(src : String) -> ServiceConf raise RefusedfnLoad a ServiceConf from a JSON config string, applying the reference-style defaults for every omitted field (an empty {} yields exactly ServiceConf::new()). This is the lenient loader mirroring conf.Load with ,optional/,default= struct tags: unlike the strict derived FromJson — reachable via @json.from_json and requiring every field present — a partial config is filled from the same defaults new() uses. Keys are matched canonically, so Name/Host/Port/Timeout and moonzero's own timeout_ms/log_level spellings all load. Raises Refused on malformed JSON, a non-object root, a field of the wrong type, or a log level outside debug|info|error|severe.
fn ServiceConf::from_yaml(src : String) -> ServiceConf raise RefusedfnLoad a ServiceConf from a **YAML** config string — the format actually ships (etc/*.yaml) — with the same lenient, default-filling semantics as from_json: an empty document yields exactly ServiceConf::new(), and each omitted field falls back to its new() default. The YAML is parsed by the self-built yaml_parse (block mappings, nesting, sequences, scalars, comments) into a Json object, then decoded by the shared field reader — so JSON and YAML configs agree field-for-field. Raises Refused on malformed YAML, a non-mapping root, a field of the wrong type, or a log level outside debug|info|error|severe.