Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HOCON Substitution default value

In HOCON and Typesafe Config, How do I set the default value in case of substitution.

Does it supports something like this ??

${server.host: 'localhost'} -> If server.host set(Either in the same configu files or through environement setting) it substitutes that if not set choose the default value

like image 720
Ysak Avatar asked Aug 08 '16 06:08

Ysak


1 Answers

From the official docs on substitutions:

If a substitution with the ${?foo} syntax is undefined:

  • if it is the value of an object field then the field should not be created. If the field would have overridden a previously-set value for the same field, then the previous value remains.

So here is one possible workaround using object merging:

defaults {
  foo: "default Value"
}

item = ${defaults} {
  foo: ${?bar}
}

Or even simplier:

item = {
  foo: "default Value"
  foo: ${?bar}
}
like image 53
Vadzim Avatar answered Sep 19 '22 00:09

Vadzim