Settings#
The settings of a yuno, defining the tree of gobj’s to be created and their configuration, can be done with the function:
PUBLIC char *json_config(
BOOL print_verbose_config,
BOOL print_final_config,
const char *fixed_config,
const char *variable_config,
const char *config_json_file,
const char *parameter_config,
pe_flag_t quit
);
Source code in:
The json_config()
function is a utility in Yuneta designed to generate a final JSON configuration by merging multiple JSON inputs. It supports advanced features like comment handling, variable substitution, and range-based expansion. The function can output the resulting configuration, validate it, and handle errors robustly.
The json_config()
function merges multiple JSON configurations into a single final configuration string, following a specific order of precedence. It also includes features like comment handling, variable substitution, and range-based expansion for flexibility and advanced use cases.
The return of json_config()
is a string that must be converted to JSON.
Global Settings#
If the final JSON has a key global
, his value will be used as
the argument jn_global_settings
in gobj_start_up
,
and will be merge to kw
when creating a gobj
.
Features#
1. Global Variable Substitution#
The function replaces strings enclosed in (^^ ^^)
with corresponding values from the __json_config_variables__
dictionary. This dictionary includes global variables returned by gobj_global_variables()
.
Predefined Variables in __json_config_variables__
#
Variable |
Description |
---|---|
|
Node owner of the Yuno. |
|
Realm ID of the Yuno. |
|
Realm owner of the Yuno. |
|
Realm role of the Yuno. |
|
Name of the realm. |
|
Environment of the realm. |
|
Unique ID of the Yuno. |
|
Role of the Yuno. |
|
Name of the Yuno. |
|
Tag of the Yuno. |
|
Role and name of the Yuno. |
|
Hostname of the system. |
|
System name (Linux only). |
|
Node name (Linux only). |
|
System version (Linux only). |
|
System release (Linux only). |
|
Machine type (Linux only). |
3. Range-Based Expansion#
Expands JSON objects based on ranges defined within the input JSON. For example:
{ “range”: [12000, 12002], “content”: { “item(^^range^^)”: { “id”: “(^^range^^)” } } }
Will expand into:
{ “item12000”: { “id”: “12000” }, “item12001”: { “id”: “12001” }, “item12002”: { “id”: “12002” } }
4. Order of Precedence#
The function processes inputs in the following order:
fixed_config
: Non-writable configuration.variable_config
: Writable configuration.config_json_file
: Overwritesvariable_config
if specified.parameter_config
: Final overwrites.
Behavior#
Error Handling: The function exits or continues based on the
quit
parameter if a JSON parsing error occurs.Verbose Outputs: If
print_verbose_config
orprint_final_config
isTRUE
, the function prints the configurations and exits.
Return Value#
Returns a dynamically allocated string containing the final JSON configuration.
Important: The returned string must be freed using
jsonp_free()
to avoid memory leaks.
2. Comment Handling#
Supports single-line comments using the syntax
##^
in JSON strings.