diff --git a/README.md b/README.md index 24c0fb4..23c7115 100644 --- a/README.md +++ b/README.md @@ -21,34 +21,31 @@ libraryDependencies += "io.github.jonas" %% "circe-config" % "0.1.1" ## Example ```scala -import com.typesafe.config.ConfigFactory -import io.circe.generic.auto._ -import io.github.jonas.circe.config.syntax._ - -case class ServerSettings(host: String, port: Int, ssl: Option[String]) -case class HttpSettings(server: ServerSettings, version: Double) -case class AppSettings(http: HttpSettings) - -val config = ConfigFactory.parseString(""" - http { - version = 1.1 - server { - host = localhost - port = 8080 - } - } -""") - -val serverSettings = config.as[ServerSettings]("http.server") -// => serverSettings: Either[io.circe.Error,ServerSettings] = Right(ServerSettings(localhost,8080,None)) - -val httpSettings = config.as[ServerSettings]("http") -// => httpSettings: Either[io.circe.Error,HttpSettings] = Right(HttpSettings(ServerSettings(localhost,8080,None),1.1)) - -val appSettings = config.as[AppSettings] -// => appSettings: Either[io.circe.Error,AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080,None),1.1))) +scala> import com.typesafe.config.{ ConfigFactory, ConfigMemorySize } +scala> import io.circe.generic.auto._ +scala> import io.github.jonas.circe.config.syntax._ +scala> import scala.concurrent.duration.FiniteDuration + +scala> case class ServerSettings(host: String, port: Int, timeout: FiniteDuration, maxUpload: ConfigMemorySize) +scala> case class HttpSettings(server: ServerSettings, version: Option[Double]) +scala> case class AppSettings(http: HttpSettings) + +scala> val config = ConfigFactory.load() + +scala> config.as[ServerSettings]("http.server") +res0: Either[io.circe.Error,ServerSettings] = Right(ServerSettings(localhost,8080,5 seconds,ConfigMemorySize(5242880))) + +scala> config.as[HttpSettings]("http") +res1: Either[io.circe.Error,HttpSettings] = Right(HttpSettings(ServerSettings(localhost,8080,5 seconds,ConfigMemorySize(5242880)),Some(1.1))) + +scala> config.as[AppSettings] +res2: Either[io.circe.Error,AppSettings] = Right(AppSettings(HttpSettings(ServerSettings(localhost,8080,5 seconds,ConfigMemorySize(5242880)),Some(1.1)))) ``` +Based on this [application.conf]. + + [application.conf]: https://github.com/jonas/circe-config/tree/master/src/test/resources/application.conf + ## Releasing To release version `x.y.z` run: diff --git a/build.sbt b/build.sbt index c896c40..83f9af3 100644 --- a/build.sbt +++ b/build.sbt @@ -59,6 +59,7 @@ libraryDependencies ++= Seq( autoAPIMappings := true doctestTestFramework := DoctestTestFramework.ScalaTest +doctestMarkdownEnabled := true doctestWithDependencies := false scalacOptions in (Compile,doc) := Seq( "-groups", diff --git a/src/test/resources/application.conf b/src/test/resources/application.conf new file mode 100644 index 0000000..af06234 --- /dev/null +++ b/src/test/resources/application.conf @@ -0,0 +1,9 @@ +http { + version = 1.1 + server { + host = localhost + port = 8080 + timeout = 5 s + maxUpload = 5M + } +}