j3d
j3d

Reputation: 9724

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.

Upvotes: 9

Views: 3578

Answers (1)

Bryn Keller
Bryn Keller

Reputation: 989

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.

Upvotes: 6

Related Questions