Modules
The following sections describe the additional modules.
Circe
The ciris-circe
module provides ConfigDecoder
s for JSON using Circe.
import ciris._
import ciris.circe._
import io.circe.Decoder
case class SerialNumber(value: String)
object SerialNumber {
implicit val serialNumberDecoder: Decoder[SerialNumber] =
Decoder[String].map(apply)
implicit val serialNumberConfigDecoder: ConfigDecoder[String, SerialNumber] =
circeConfigDecoder("SerialNumber")
}
env("SERIAL").as[SerialNumber]
// res0: ConfigValue[Effect, SerialNumber] = ConfigValue$1967244520
Circe YAML
The ciris-circe-yaml
module provides ConfigDecoder
s for YAML using circe-yaml
.
import ciris._
import ciris.circe.yaml._
import io.circe.Decoder
case class SerialNumber(value: String)
object SerialNumber {
implicit val serialNumberDecoder: Decoder[SerialNumber] =
Decoder[String].map(apply)
implicit val serialNumberConfigDecoder: ConfigDecoder[String, SerialNumber] =
circeYamlConfigDecoder("SerialNumber")
}
env("SERIAL").as[SerialNumber]
// res2: ConfigValue[Effect, SerialNumber] = ConfigValue$331460105
Enumeratum
The ciris-enumeratum
module provides ConfigDecoder
s for Enumeratum enumerations.
For regular Enum
s, also mix in CirisEnum
to derive a ConfigDecoder
instance.
import ciris.env
import enumeratum.{CirisEnum, Enum, EnumEntry}
import enumeratum.EnumEntry.Lowercase
sealed trait Suit extends EnumEntry with Lowercase
object Suit extends Enum[Suit] with CirisEnum[Suit] {
case object Clubs extends Suit
case object Diamonds extends Suit
case object Hearts extends Suit
case object Spades extends Suit
val values = findValues
}
env("SUIT").as[Suit]
// res4: ciris.ConfigValue[ciris.package.Effect, Suit] = ConfigValue$1119468609
For ValueEnum
s, also mix in the matching CirisValueEnum
to derive a ConfigDecoder
instance.
import ciris.env
import enumeratum.values.{StringCirisEnum, StringEnum, StringEnumEntry}
sealed abstract class Color(val value: String) extends StringEnumEntry
object Color extends StringEnum[Color] with StringCirisEnum[Color] {
case object Red extends Color("red")
case object Green extends Color("green")
case object Blue extends Color("blue")
val values = findValues
}
env("COLOR").as[Color]
// res6: ciris.ConfigValue[ciris.package.Effect, Color] = ConfigValue$1002683590
Http4s
The ciris-http4s
module provides ConfigDecoder
s for the http4s Uri
type.
import ciris.env
import ciris.http4s._
import org.http4s.Uri
env("URI").as[Uri]
// res8: ciris.ConfigValue[ciris.package.Effect, Uri] = ConfigValue$419037575
Refined
The ciris-refined
module provides ConfigDecoder
s for refined refinement types.
import ciris.env
import ciris.refined._
import eu.timepit.refined.types.numeric.PosInt
env("POS_INT").as[PosInt]
// res10: ciris.ConfigValue[ciris.package.Effect, PosInt] = ConfigValue$811280901
Squants
The ciris-squants
module provides ConfigDecoder
s for squants quantities.
import ciris.env
import ciris.squants._
import squants.market.Money
env("MONEY").as[Money]
// res12: ciris.ConfigValue[ciris.package.Effect, Money] = ConfigValue$749926997