Skip to content

Commit

Permalink
Update zio-config to 4.0.1 (#388)
Browse files Browse the repository at this point in the history
  • Loading branch information
drmarjanovic authored Feb 4, 2024
1 parent 1e3980a commit 7baa326
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ lazy val example =
publish / skip := true,
libraryDependencies ++= List(
"dev.zio" %% "zio" % "2.0.21",
"dev.zio" %% "zio-config" % "3.0.7",
"dev.zio" %% "zio-config-magnolia" % "3.0.7",
"dev.zio" %% "zio-config-typesafe" % "3.0.7",
"dev.zio" %% "zio-config" % "4.0.1",
"dev.zio" %% "zio-config-magnolia" % "4.0.1",
"dev.zio" %% "zio-config-typesafe" % "4.0.1",
"dev.zio" %% "zio-http" % "0.0.5",
"dev.zio" %% "zio-json" % "0.6.2",
"dev.zio" %% "zio-schema" % "0.4.17",
Expand Down
5 changes: 2 additions & 3 deletions modules/example/src/main/scala/example/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import example.external.github.RepoFetcher
import sttp.client3.SttpBackend
import sttp.client3.httpclient.zio.HttpClientZioBackend
import zio._
import zio.config.getConfig
import zio.elasticsearch.{ElasticConfig, ElasticExecutor, ElasticRequest, Elasticsearch}
import zio.http.{Server, ServerConfig}

Expand All @@ -32,7 +31,7 @@ import scala.util.Using
object Main extends ZIOAppDefault {

override def run: Task[ExitCode] = {
val elasticConfigLive = ZLayer(getConfig[ElasticsearchConfig].map(es => ElasticConfig(es.host, es.port)))
val elasticConfigLive = ZLayer(ZIO.serviceWith[ElasticsearchConfig](es => ElasticConfig(es.host, es.port)))

(prepare *> runServer).provide(
AppConfig.live,
Expand Down Expand Up @@ -71,7 +70,7 @@ object Main extends ZIOAppDefault {
val serverConfigLive = ZLayer.fromFunction((http: HttpConfig) => ServerConfig.default.port(http.port))

(for {
http <- getConfig[HttpConfig]
http <- ZIO.service[HttpConfig]
_ <- ZIO.logInfo(s"Starting an HTTP service on port: ${http.port}")
routes = HealthCheck.Route ++ Repositories.Routes
_ <- Server.serve(routes)
Expand Down
14 changes: 6 additions & 8 deletions modules/example/src/main/scala/example/config/AppConfig.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@

package example.config

import zio.Layer
import zio.config.ReadError
import zio.config.magnolia.descriptor
import zio.config.syntax._
import zio.config.typesafe.TypesafeConfig
import zio.config.magnolia.deriveConfig
import zio.config.typesafe.TypesafeConfigProvider
import zio.{Config, Layer, ZLayer}

final case class AppConfig(http: HttpConfig, elasticsearch: ElasticsearchConfig)

object AppConfig {
lazy val live: Layer[ReadError[String], ElasticsearchConfig with HttpConfig] = {
val config = TypesafeConfig.fromResourcePath(descriptor[AppConfig])
config.narrow(_.elasticsearch) >+> config.narrow(_.http)
lazy val live: Layer[Config.Error, ElasticsearchConfig with HttpConfig] = {
val config = TypesafeConfigProvider.fromResourcePath().load(deriveConfig[AppConfig])
ZLayer.fromZIO(config.map(_.elasticsearch)) ++ ZLayer.fromZIO(config.map(_.http))
}
}

0 comments on commit 7baa326

Please sign in to comment.