All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala-finch.Server.mustache Maven / Gradle / Ivy

package {{packageName}}

import io.finch._
import io.finch.circe._
import io.circe.{Decoder, ObjectEncoder}
import io.circe.generic.auto._
import io.circe.generic.semiauto
import io.circe.generic.semiauto._
import io.circe.java8.time._
import com.twitter.finagle.Http
import com.twitter.finagle.util.LoadService
import com.twitter.util.{Await, Future}

{{#imports}}import {{import}}
{{/imports}}

class Server {

  // Loads implementation defined in resources/META-INF/services/{{packageName}}.DataAccessor
  val impls: Seq[DataAccessor] = LoadService[DataAccessor]()
  val db = if (impls.isEmpty) new DataAccessor { } else impls.head

  val service = endpoint.makeService(db)

  val server = Http.serve(":8080", service) //creates service

  def close(): Future[Unit] = {
    Await.ready(server.close())
  }
}

/**
 * Launches the API service when the system is ready.
 */
object Server extends Server with App {
  Await.ready(server)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy