Skip to content

Commit

Permalink
add smithy4s-consul-middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
bpholt committed Jul 24, 2024
1 parent 6bf5db9 commit 02ca5d5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
22 changes: 21 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ ThisBuild / mergifySuccessConditions += MergifyCondition.Custom("#approved-revie

lazy val log4catsVersion = "2.7.0"

lazy val root = tlCrossRootProject.aggregate(`http4s-consul-middleware`)
lazy val root = tlCrossRootProject.aggregate(
`http4s-consul-middleware`,
`smithy4s-consul-middleware`,
)

lazy val `http4s-consul-middleware` = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
Expand Down Expand Up @@ -79,3 +82,20 @@ lazy val `http4s-consul-middleware` = crossProject(JSPlatform, JVMPlatform)
"io.github.cquiroz" %%% "scala-java-time-tzdb" % "2.6.0" % Test,
)
)

lazy val `smithy4s-consul-middleware` = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("smithy4s"))
.settings(
description := "smithy4s middleware to rewrite URLs back to the consul://{service} format expected by http4s-consul-middleware",
tpolecatScalacOptions += ScalacOptions.release("8"),
tlVersionIntroduced := Map("3" -> "0.3.2", "2.12" -> "0.3.2", "2.13" -> "0.3.2"),
libraryDependencies ++= {
val http4sVersion = "0.23.27"

Seq(
"org.http4s" %%% "http4s-client" % http4sVersion,
"com.disneystreaming.smithy4s" %% "smithy4s-core" % "0.18.23",
)
},
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.dwolla.consul.smithy4s

import cats.effect.MonadCancelThrow
import org.http4s.client.Client
import org.http4s.syntax.all._
import smithy4s.{Endpoint, Service}

class ReconsulifyMiddleware[F[_] : MonadCancelThrow] extends Endpoint.Middleware[Client[F]] {
override def prepare[Alg[_[_, _, _, _, _]]](service: Service[Alg])
(endpoint: service.Endpoint[_, _, _, _, _]): Client[F] => Client[F] =
underlying => Client { req =>
underlying.run(req.withUri(req.uri.copy(scheme = Option(scheme"consul"))))
}
}

object ReconsulifyMiddleware {
def apply[F[_] : MonadCancelThrow]: Endpoint.Middleware[Client[F]] = new ReconsulifyMiddleware[F]
}

0 comments on commit 02ca5d5

Please sign in to comment.