Skip to content

Instantly share code, notes, and snippets.

@yasuabe
Created April 14, 2019 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasuabe/7b200f90e6a4e8205f36b7af28fcc6fd to your computer and use it in GitHub Desktop.
Save yasuabe/7b200f90e6a4e8205f36b7af28fcc6fd to your computer and use it in GitHub Desktop.
Hello World using Ciris
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