Last active
May 25, 2024 10:20
-
-
Save dacr/92179e9589f18a08784a729137fc85ec to your computer and use it in GitHub Desktop.
ZIO learning - application configuration / published by https://github.com/dacr/code-examples-manager #df673a20-1dd6-41f1-af38-7390da22d64d/e667d0ed85e7c4de729b618a91346c9ce373711e
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
// summary : ZIO learning - application configuration | |
// keywords : scala, zio, learning, pure-functional, typesafeconfig, config,, @testable | |
// publish : gist | |
// authors : David Crosson | |
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
// id : df673a20-1dd6-41f1-af38-7390da22d64d | |
// created-on : 2021-03-29T19:16:09Z | |
// managed-by : https://github.com/dacr/code-examples-manager | |
// run-with : scala-cli $file | |
// --------------------- | |
//> using scala "3.4.2" | |
//> using dep "dev.zio::zio:2.0.13" | |
//> using dep "dev.zio::zio-config:4.0.0-RC14" | |
//> using dep "dev.zio::zio-config-typesafe:4.0.0-RC14" | |
//> using dep "dev.zio::zio-config-magnolia:4.0.0-RC14" | |
//> using dep "dev.zio::zio-config-refined:4.0.0-RC14" // type-level predicates which constrain the set of values described for data types. | |
// --------------------- | |
import zio.* | |
import zio.config.* | |
import zio.config.typesafe.* | |
import zio.config.magnolia.* | |
case class Truc(name: String) | |
case class MyConfig(truc: Truc) | |
object Encapsulated extends ZIOAppDefault { | |
// ------------------------------------------------------------- | |
val hoconConfigSource = | |
ConfigProvider.fromHoconString( | |
input = s"""truc { | |
| name=blah | |
|} | |
|""".stripMargin | |
) | |
// ------------------------------------------------------------- | |
val logic = for { | |
config <- hoconConfigSource.load(deriveConfig[MyConfig]) | |
_ <- Console.printLine(config.truc.name) | |
} yield () | |
// ------------------------------------------------------------- | |
override def run = { | |
logic | |
} | |
} | |
Encapsulated.main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment