Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zio-http 3.0.0-RC9 #873

Merged
merged 1 commit into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/reconfigurable-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ object ConfigurableLoggerApp extends ZIOAppDefault {
_ <- ZIO.logDebug("Done") @@ LogAnnotation.TraceId(traceId)
} yield ()

val httpApp: HttpApp[LoggerConfigurer] =
ApiHandlers.routes("example" :: Nil).toHttpApp @@ Middleware.basicAuth("admin", "admin")
val httpApp: Routes[LoggerConfigurer with Any, Nothing] =
ApiHandlers.routes("example" :: Nil) @@ Middleware.basicAuth("admin", "admin")

override def run: ZIO[Scope, Any, ExitCode] =
(for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,42 @@
*/
package zio.logging.api.http

import zio.http.{ Handler, Route, Routes }
import zio.ZIO
import zio.http.{ Route, Routes }
import zio.logging.LoggerConfigurer
import zio.logging.api.http.ApiDomain.Error
import zio.{ LogLevel, ZIO }

object ApiHandlers {

def getLoggerConfigs(rootPath: Seq[String] = Seq.empty): Route[LoggerConfigurer, Nothing] =
ApiEndpoints
.getLoggerConfigs(rootPath)
.implement {
Handler.fromFunctionZIO[Unit] { _ =>
LoggerConfigurer
.getLoggerConfigs()
.map(_.map(ApiDomain.LoggerConfig.from))
.mapError(_ => Error.Internal())
}
.implement { _ =>
LoggerConfigurer
.getLoggerConfigs()
.map(_.map(ApiDomain.LoggerConfig.from))
.mapError(_ => Error.Internal())

}

def getLoggerConfig(rootPath: Seq[String] = Seq.empty): Route[LoggerConfigurer, Nothing] =
ApiEndpoints
.getLoggerConfig(rootPath)
.implement {
Handler.fromFunctionZIO[String] { name =>
LoggerConfigurer.getLoggerConfig(name).mapError(_ => Error.Internal()).flatMap {
case Some(r) => ZIO.succeed(ApiDomain.LoggerConfig.from(r))
case _ => ZIO.fail(Error.NotFound())
}
.implement { name =>
LoggerConfigurer.getLoggerConfig(name).mapError(_ => Error.Internal()).flatMap {
case Some(r) => ZIO.succeed(ApiDomain.LoggerConfig.from(r))
case _ => ZIO.fail(Error.NotFound())
}
}

def setLoggerConfigs(rootPath: Seq[String] = Seq.empty): Route[LoggerConfigurer, Nothing] =
ApiEndpoints
.setLoggerConfig(rootPath)
.implement {
Handler.fromFunctionZIO[(String, LogLevel)] { case (name, logLevel) =>
LoggerConfigurer
.setLoggerConfig(name, logLevel)
.map(ApiDomain.LoggerConfig.from)
.mapError(_ => Error.Internal())
}
.implement { case (name, logLevel) =>
LoggerConfigurer
.setLoggerConfig(name, logLevel)
.map(ApiDomain.LoggerConfig.from)
.mapError(_ => Error.Internal())
}

def routes(rootPath: Seq[String] = Seq.empty): Routes[LoggerConfigurer, Nothing] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ object ConfigurableLoggerApp extends ZIOAppDefault {
_ <- ZIO.logDebug("Done") @@ LogAnnotation.TraceId(traceId)
} yield ()

val httpApp: HttpApp[LoggerConfigurer] =
ApiHandlers.routes("example" :: Nil).toHttpApp @@ Middleware.basicAuth("admin", "admin")
val httpApp: Routes[LoggerConfigurer with Any, Nothing] =
ApiHandlers.routes("example" :: Nil) @@ Middleware.basicAuth("admin", "admin")

override def run: ZIO[Scope, Any, ExitCode] =
(for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object ApiHandlersSpec extends ZIOSpecDefault {

for {
request <- ZIO.attempt(Request.get(URL.decode("/example/logger").toOption.get))
response <- routes.toHttpApp.runZIO(request)
response <- routes.runZIO(request)
content <- HttpCodec.content[List[ApiDomain.LoggerConfig]].decodeResponse(response)
} yield assertTrue(response.status.isSuccess) && assertTrue(
content == List(ApiDomain.LoggerConfig("root", LogLevel.Info))
Expand All @@ -42,7 +42,7 @@ object ApiHandlersSpec extends ZIOSpecDefault {
val routes = ApiHandlers.routes("example" :: Nil)
for {
request <- ZIO.attempt(Request.get(URL.decode("/example/logger/example.Service").toOption.get))
response <- routes.toHttpApp.runZIO(request)
response <- routes.runZIO(request)
content <- HttpCodec.content[ApiDomain.LoggerConfig].decodeResponse(response)
} yield assertTrue(response.status.isSuccess) && assertTrue(
content == ApiDomain.LoggerConfig("example.Service", LogLevel.Info)
Expand All @@ -59,7 +59,7 @@ object ApiHandlersSpec extends ZIOSpecDefault {
HttpCodec.content[LogLevel].encodeRequest(LogLevel.Warning).body
)
)
response <- routes.toHttpApp.runZIO(request)
response <- routes.runZIO(request)
content <- HttpCodec.content[ApiDomain.LoggerConfig].decodeResponse(response)
} yield assertTrue(response.status.isSuccess) && assertTrue(
content == ApiDomain.LoggerConfig("example.Service", LogLevel.Warning)
Expand Down
2 changes: 1 addition & 1 deletion project/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ object Versions {
val zioConfig = "4.0.2"
val zioParser = "0.1.10"
val zioPrelude = "1.0.0-RC28"
val zioHttp = "3.0.0-RC6"
val zioHttp = "3.0.0-RC9"
val log4jVersion = "2.23.1"
}