-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/0.23-scala3' into merge-0.23-to-…
…0.23-scala3
- Loading branch information
Showing
10 changed files
with
42 additions
and
259 deletions.
There are no files selected for viewing
6 changes: 0 additions & 6 deletions
6
src/main/g8/$if(graal_native_image.truthy)$native-image-readme.md$endif$
This file was deleted.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
name = quickstart | ||
organization = com.example | ||
package = $organization$.$name;format="norm,word"$ | ||
|
||
scala_version = 2.13.14 | ||
# graal_vm_specific | ||
graal_native_image = true | ||
is_linux_build = false | ||
scala_assembly_target = scala-2.13 |
180 changes: 0 additions & 180 deletions
180
...native_image.truthy)$META-INF$endif$/native-image/$package__packaged$/reflect-config.json
This file was deleted.
Oops, something went wrong.
15 changes: 6 additions & 9 deletions
15
src/main/g8/src/main/scala/$package__packaged$/$name__Camel$Routes.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,30 @@ | ||
package $package$ | ||
|
||
import cats.effect.Sync | ||
import cats.implicits._ | ||
import cats.syntax.all.* | ||
import org.http4s.HttpRoutes | ||
import org.http4s.dsl.Http4sDsl | ||
|
||
object $name;format="Camel"$Routes { | ||
object $name;format="Camel"$Routes: | ||
|
||
def jokeRoutes[F[_]: Sync](J: Jokes[F]): HttpRoutes[F] = { | ||
def jokeRoutes[F[_]: Sync](J: Jokes[F]): HttpRoutes[F] = | ||
val dsl = new Http4sDsl[F]{} | ||
import dsl._ | ||
import dsl.* | ||
HttpRoutes.of[F] { | ||
case GET -> Root / "joke" => | ||
for { | ||
joke <- J.get | ||
resp <- Ok(joke) | ||
} yield resp | ||
} | ||
} | ||
|
||
def helloWorldRoutes[F[_]: Sync](H: HelloWorld[F]): HttpRoutes[F] = { | ||
def helloWorldRoutes[F[_]: Sync](H: HelloWorld[F]): HttpRoutes[F] = | ||
val dsl = new Http4sDsl[F]{} | ||
import dsl._ | ||
import dsl.* | ||
HttpRoutes.of[F] { | ||
case GET -> Root / "hello" / name => | ||
for { | ||
greeting <- H.hello(HelloWorld.Name(name)) | ||
resp <- Ok(greeting) | ||
} yield resp | ||
} | ||
} | ||
} |
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
22 changes: 9 additions & 13 deletions
22
src/main/g8/src/main/scala/$package__packaged$/HelloWorld.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,31 @@ | ||
package $package$ | ||
|
||
import cats.Applicative | ||
import cats.implicits._ | ||
import cats.syntax.all.* | ||
import io.circe.{Encoder, Json} | ||
import org.http4s.EntityEncoder | ||
import org.http4s.circe._ | ||
import org.http4s.circe.* | ||
|
||
trait HelloWorld[F[_]]{ | ||
trait HelloWorld[F[_]]: | ||
def hello(n: HelloWorld.Name): F[HelloWorld.Greeting] | ||
} | ||
|
||
object HelloWorld { | ||
object HelloWorld: | ||
final case class Name(name: String) extends AnyVal | ||
/** | ||
* More generally you will want to decouple your edge representations from | ||
* your internal data structures, however this shows how you can | ||
* create encoders for your data. | ||
**/ | ||
final case class Greeting(greeting: String) extends AnyVal | ||
object Greeting { | ||
implicit val greetingEncoder: Encoder[Greeting] = new Encoder[Greeting] { | ||
object Greeting: | ||
given Encoder[Greeting] = new Encoder[Greeting]: | ||
final def apply(a: Greeting): Json = Json.obj( | ||
("message", Json.fromString(a.greeting)), | ||
) | ||
} | ||
implicit def greetingEntityEncoder[F[_]]: EntityEncoder[F, Greeting] = | ||
|
||
given [F[_]]: EntityEncoder[F, Greeting] = | ||
jsonEncoderOf[F, Greeting] | ||
} | ||
|
||
def impl[F[_]: Applicative]: HelloWorld[F] = new HelloWorld[F]{ | ||
def impl[F[_]: Applicative]: HelloWorld[F] = new HelloWorld[F]: | ||
def hello(n: HelloWorld.Name): F[HelloWorld.Greeting] = | ||
Greeting("Hello, " + n.name).pure[F] | ||
} | ||
} |
42 changes: 17 additions & 25 deletions
42
src/main/g8/src/main/scala/$package__packaged$/Jokes.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,33 @@ | ||
package $package$ | ||
|
||
import cats.effect.Concurrent | ||
import cats.implicits._ | ||
import cats.syntax.all.* | ||
import io.circe.{Encoder, Decoder} | ||
import io.circe.generic.semiauto._ | ||
import org.http4s._ | ||
import org.http4s.implicits._ | ||
import org.http4s.* | ||
import org.http4s.implicits.* | ||
import org.http4s.client.Client | ||
import org.http4s.client.dsl.Http4sClientDsl | ||
import org.http4s.circe._ | ||
import org.http4s.Method._ | ||
import org.http4s.circe.* | ||
import org.http4s.Method.* | ||
|
||
trait Jokes[F[_]]{ | ||
trait Jokes[F[_]]: | ||
def get: F[Jokes.Joke] | ||
} | ||
|
||
object Jokes { | ||
def apply[F[_]](implicit ev: Jokes[F]): Jokes[F] = ev | ||
object Jokes: | ||
def apply[F[_]](using ev: Jokes[F]): Jokes[F] = ev | ||
|
||
final case class Joke(joke: String) extends AnyVal | ||
object Joke { | ||
implicit val jokeDecoder: Decoder[Joke] = deriveDecoder[Joke] | ||
implicit def jokeEntityDecoder[F[_]: Concurrent]: EntityDecoder[F, Joke] = | ||
jsonOf | ||
implicit val jokeEncoder: Encoder[Joke] = deriveEncoder[Joke] | ||
implicit def jokeEntityEncoder[F[_]]: EntityEncoder[F, Joke] = | ||
jsonEncoderOf | ||
} | ||
final case class Joke(joke: String) | ||
object Joke: | ||
given Decoder[Joke] = Decoder.derived[Joke] | ||
given [F[_]: Concurrent]: EntityDecoder[F, Joke] = jsonOf | ||
given Encoder[Joke] = Encoder.AsObject.derived[Joke] | ||
given [F[_]]: EntityEncoder[F, Joke] = jsonEncoderOf | ||
|
||
final case class JokeError(e: Throwable) extends RuntimeException | ||
|
||
def impl[F[_]: Concurrent](C: Client[F]): Jokes[F] = new Jokes[F]{ | ||
def impl[F[_]: Concurrent](C: Client[F]): Jokes[F] = new Jokes[F]: | ||
val dsl = new Http4sClientDsl[F]{} | ||
import dsl._ | ||
def get: F[Jokes.Joke] = { | ||
import dsl.* | ||
def get: F[Jokes.Joke] = | ||
C.expect[Joke](GET(uri"https://icanhazdadjoke.com/")) | ||
.adaptError{ case t => JokeError(t)} // Prevent Client Json Decoding Failure Leaking | ||
} | ||
} | ||
} |
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
Oops, something went wrong.