Typesafe/Hocon config: variable substitution: refe

2020-08-10 09:44发布

问题:

We have a project with huge configuration files built using hocon configs. There is an intention to use variables where possible to create template_section and setup some values in template based on some options.

The problem is that while using variables in this config, I have to refer to absolute path all the time. Is it possible somehow to use canonical name (if properties located on same level)?

Example:

foo {
    bar = 4
    baz = ${foo.bar} // work perfect
    baz = ${[this].bar} // can I do smth like that? Any ideas.
}

More real-life example. What I'm actually looking for is general OOP abilities in building hocon configs. I have some parent configuration template_config with important_option inside that really depends on implementation: custom_config1 or custom_config2 , what I have to do currently is to implement important_option in both children configurations because with absolute pathes I have to refer to custom config sectsions names.

custom_config1: $template_config {
    child_option = child_value1
}

custom_config2: $template_config {
    child_option = child_value2
}

template_config {
    important_option = ${child_option} // NOT POSSIBLE
    child_option = not_implemented
}