Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typesafe Config: How to Create Conditional Configurations

Does Typesafe Config allow to create conditional configurations?

I need to set a key depending on the value of another key:

ssl = true

#if ssl == true
host = "https://localhost"
#else
host = "http://localhost"
#end if

Of course the code above does't work... I just wanted to illustrate what I'm trying to do.

like image 888
j3d Avatar asked Jul 23 '14 17:07

j3d


1 Answers

Not directly, no. For the particular example you gave, you could use optional properties:

protocol = "http"
protocol = ${?MY_PROTOCOL}

host = ${protocol}://localhost

Then if your application was started with either -Dprotocol=https as an argument to java, or with MY_PROTOCOL=https as an environment variable, you'd get https in the host.

like image 100
Bryn Keller Avatar answered Nov 24 '22 19:11

Bryn Keller