Last active
April 28, 2023 06:45
-
-
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/57c0ca386497f37da7a50b130e7e1cc91ed40c7a
This file contains 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.2.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