Created
April 14, 2019 14:09
-
-
Save yasuabe/7b200f90e6a4e8205f36b7af28fcc6fd to your computer and use it in GitHub Desktop.
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.{ConfigEntry, ConfigErrors, ConfigResult, env, loadConfig, file} | |
import ciris.generic._ | |
case class Config(name: String) | |
object Main { | |
def main(args: Array[String]): Unit = { | |
val entry: ConfigEntry[Id, String, String, String] = env[String]("NAME") | |
val result: ConfigResult[Id, Config] = loadConfig(entry) { name => | |
Config(name) | |
} | |
val config: Id[Either[ConfigErrors, Config]] = result.result | |
val greeting = config.fold(_.message, c => s"Hello, ${c.name}!") | |
println(greeting) // "Hello, World!" または "- Missing environment variable [NAME]." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment