Created
April 14, 2019 14:32
-
-
Save yasuabe/6481307d649af92972cfa53cfc8a424a to your computer and use it in GitHub Desktop.
multi env hello world using Ciris
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package exercise.ciris.qiita1 | |
import ciris.api.Id | |
import ciris.{ConfigResult, env, withValues, loadConfig} | |
import ciris.generic._ | |
object MainMulti { | |
case class Config(name: String) | |
val config: ConfigResult[Id, Config] = | |
withValues(env[Option[String]]("APP_ENV")) { | |
case Some("PRODUCTION") => loadConfig(env[String]("NAME"))(Config) | |
case _ => loadConfig { Config("local") } | |
} | |
def main(args: Array[String]): Unit = { | |
val greeting = config.result.fold(_.message, c => s"Hello, ${c.name}!") | |
println(greeting) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment