akka.grpc.gen.scaladsl.ScalaClientCodeGenerator.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of akka-grpc-codegen_2.12 Show documentation
Show all versions of akka-grpc-codegen_2.12 Show documentation
Akka gRPC - Support for building streaming gRPC servers and clients on top of Akka Streams.
/*
* Copyright (C) 2018-2021 Lightbend Inc.
*/
package akka.grpc.gen.scaladsl
import scala.collection.immutable
import akka.grpc.gen.{ BuildInfo, CodeGenerator, Logger }
import com.google.protobuf.compiler.PluginProtos.CodeGeneratorResponse
import protocbridge.Artifact
import templates.ScalaClient.txt._
trait ScalaClientCodeGenerator extends ScalaCodeGenerator {
override def name = "akka-grpc-scaladsl-client"
override def perServiceContent = super.perServiceContent + generateStub
def generateStub(logger: Logger, service: Service): immutable.Seq[CodeGeneratorResponse.File] = {
val b = CodeGeneratorResponse.File.newBuilder()
b.setContent(Client(service).body)
b.setName(s"${service.packageDir}/${service.name}Client.scala")
logger.info(s"Generating Akka gRPC client for ${service.packageName}.${service.name}")
immutable.Seq(b.build)
}
override val suggestedDependencies = (scalaBinaryVersion: CodeGenerator.ScalaBinaryVersion) =>
// TODO: remove grpc-stub dependency once we have a akka-http based client #193
Artifact("io.grpc", "grpc-stub", BuildInfo.grpcVersion) +: super.suggestedDependencies(scalaBinaryVersion)
}
object ScalaClientCodeGenerator extends ScalaClientCodeGenerator