本文整理汇总了Scala中play.api.Mode类的典型用法代码示例。如果您正苦于以下问题:Scala Mode类的具体用法?Scala Mode怎么用?Scala Mode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mode类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: injectorModules
//设置package包名称以及导入依赖的类
package global
import actors.ChadashSystem
import com.google.inject.{Guice, Module}
import play.api.mvc.{EssentialAction, Filters}
import play.api.{Application, GlobalSettings, Logger, Mode}
import play.filters.gzip.GzipFilter
import play.filters.headers.SecurityHeadersFilter
trait AppGlobalSettings extends GlobalSettings {
private var INJECTOR: Option[com.google.inject.Injector] = None
def injectorModules(): Seq[Module]
override def onStart(app: Application) {
INJECTOR = Some(Guice.createInjector(injectorModules(): _*))
}
override def onStop(app: Application) {
Logger.info("Application shutdown...")
if(app.mode != Mode.Test)
ChadashSystem.system.shutdown()
}
override def doFilter(next: EssentialAction): EssentialAction = {
Filters(super.doFilter(next), new GzipFilter(), SecurityHeadersFilter())
}
override def getControllerInstance[A](controllerClass: Class[A]): A = {
INJECTOR match {
case Some(x) => x.getInstance(controllerClass)
case None => throw new UnsupportedOperationException("The DI framework has not been setup yet!")
}
}
}
开发者ID:lifeway,项目名称:Chadash,代码行数:37,代码来源:AppGlobalSettings.scala
示例2: IntegrationSpec
//设置package包名称以及导入依赖的类
import org.scalatestplus.play._
import org.scalatestplus.play.guice.GuiceOneServerPerSuite
import play.api.{Configuration, Mode}
import play.api.cache.{CacheApi, EhCacheModule}
import play.api.inject._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.test._
import play.api.test.Helpers._
import util.FakeCache
class IntegrationSpec extends PlaySpec with GuiceOneServerPerSuite with OneBrowserPerTest with HtmlUnitFactory {
implicit override lazy val app = new GuiceApplicationBuilder()
.overrides(bind[CacheApi].to[FakeCache])
.loadConfig(env => Configuration.load(env))
.in(Mode.Test)
.build
"Application" should {
"work from within a browser" in {
go to ("http://localhost:" + port)
pageSource must include ("Aktuelles der Fakultät Informatik")
}
}
}
开发者ID:P1tt187,项目名称:spirit-play,代码行数:30,代码来源:IntegrationSpec.scala
示例3: WebGateway
//设置package包名称以及导入依赖的类
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.softwaremill.macwire._
import controllers.{Assets, Main}
import ogr.wex.cmsfs.monitor.api.MonitorService
import org.wex.cmsfs.lagom.service.discovery.Common
import org.wex.cmsfs.lagom.service.discovery.consul.ConsulServiceLocatorComponents
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.{ApplicationLoader, BuiltInComponentsFromContext, Mode}
import router.Routes
import scala.collection.immutable
import scala.concurrent.ExecutionContext
abstract class WebGateway(context: Context) extends BuiltInComponentsFromContext(context)
with I18nComponents
with AhcWSComponents
with LagomServiceClientComponents {
override lazy val serviceInfo: ServiceInfo = ServiceInfo(
"web-gateway",
Map(
"web-gateway" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
)
)
override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
override lazy val router = {
val prefix = "/"
wire[Routes]
}
lazy val monitorService = serviceClient.implement[MonitorService]
lazy val main = wire[Main]
lazy val assets = wire[Assets]
}
class WebGatewayLoader extends ApplicationLoader {
override def load(context: Context) = {
Common.loaderEnvironment(context)
println(context.environment.mode)
context.environment.mode match {
case Mode.Dev =>
new WebGateway(context) with LagomDevModeComponents {}.application
case _ =>
new WebGateway(context) with ConsulServiceLocatorComponents {}.application
}
}
}
开发者ID:shinhwagk,项目名称:cmsfs,代码行数:53,代码来源:Loader.scala
示例4: PlayApp
//设置package包名称以及导入依赖的类
import play.api.{Application, ApplicationLoader, Environment, Mode, Play}
import play.core.server.{ServerConfig, ServerProvider}
object PlayApp extends App {
val config = ServerConfig(mode = Mode.Dev)
val application: Application = {
val environment = Environment(config.rootDir, this.getClass.getClassLoader, Mode.Dev)
val context = ApplicationLoader.createContext(environment)
val loader = ApplicationLoader(context)
loader.load(context)
}
Play.start(application)
val serverProvider: ServerProvider = ServerProvider.fromConfiguration(this.getClass.getClassLoader, config.configuration)
serverProvider.createServer(config, application)
}
开发者ID:mindfulmachines,项目名称:unus,代码行数:20,代码来源:PlayApp.scala
示例5: WebGateway
//设置package包名称以及导入依赖的类
import com.example.auction.bidding.api.BiddingService
import com.example.auction.item.api.ItemService
import com.example.auction.user.api.UserService
import com.lightbend.lagom.scaladsl.api.{ ServiceAcl, ServiceInfo }
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.softwaremill.macwire._
import com.typesafe.conductr.bundlelib.lagom.scaladsl.ConductRApplicationComponents
import controllers.{ Assets, ItemController, Main, ProfileController }
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.{ ApplicationLoader, BuiltInComponentsFromContext, Mode }
import router.Routes
import scala.collection.immutable
import scala.concurrent.ExecutionContext
abstract class WebGateway(context: Context) extends BuiltInComponentsFromContext(context)
with I18nComponents
with AhcWSComponents
with LagomServiceClientComponents {
override lazy val serviceInfo: ServiceInfo = ServiceInfo(
"web-gateway",
Map(
"web-gateway" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
)
)
override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
override lazy val router = {
val prefix = "/"
wire[Routes]
}
lazy val userService = serviceClient.implement[UserService]
lazy val itemService = serviceClient.implement[ItemService]
lazy val biddingService = serviceClient.implement[BiddingService]
lazy val main = wire[Main]
lazy val itemController = wire[ItemController]
lazy val profileController = wire[ProfileController]
lazy val assets = wire[Assets]
}
class WebGatewayLoader extends ApplicationLoader {
override def load(context: Context) = context.environment.mode match {
case Mode.Dev =>
(new WebGateway(context) with LagomDevModeComponents).application
case _ =>
(new WebGateway(context) with ConductRApplicationComponents).application
}
}
开发者ID:lagom,项目名称:online-auction-scala,代码行数:54,代码来源:Loader.scala
示例6: Module
//设置package包名称以及导入依赖的类
import com.google.inject.AbstractModule
import play.api.{Configuration, Environment, Mode}
import services.{CarStorageService, DynamoDbCarStorageService, InMemoryCarStorageService, StaticCarStorageService}
class Module(environment: Environment, configuration: Configuration) extends AbstractModule {
override def configure() = {
environment.mode match {
case Mode.Test =>
bind(classOf[CarStorageService]).to(classOf[StaticCarStorageService])
case Mode.Dev =>
bind(classOf[CarStorageService]).to(classOf[InMemoryCarStorageService])
case Mode.Prod =>
bind(classOf[CarStorageService]).to(classOf[DynamoDbCarStorageService])
}
}
}
开发者ID:ArchDev,项目名称:dynamodb-rest-api,代码行数:19,代码来源:Module.scala
示例7: TestAppComponents
//设置package包名称以及导入依赖的类
package com.grimey.utils
import java.io.File
import com.grimey.{DatabaseContextConfig, GrimeyDatabaseContext, GrimeyAppComponents}
import play.api
import play.api.{Mode, Environment, ApplicationLoader}
import play.api.ApplicationLoader.Context
import scala.concurrent.duration._
import slick.jdbc.JdbcBackend
trait TestUtils {
// Todo: This should be injected.
protected lazy val db: JdbcBackend#DatabaseDef =
new GrimeyDatabaseContext(DatabaseContextConfig(defaultTimeout = 10.seconds)).db
implicit lazy val app: api.Application = {
val appLoader = new TestAppLoader()
val context = ApplicationLoader.createContext(
new Environment(new File("."), ApplicationLoader.getClass.getClassLoader, Mode.Test)
)
appLoader.load(context)
}
}
class TestAppComponents(context: Context) extends GrimeyAppComponents(context) {
// Todo: Add test specific configuration here when applicable.
}
class TestAppLoader extends ApplicationLoader {
override def load(context: Context): api.Application = new TestAppComponents(context).application
}
开发者ID:CSGrimey,项目名称:grimey-cms-scala,代码行数:34,代码来源:TestUtils.scala
示例8: WebGateway
//设置package包名称以及导入依赖的类
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.ApplicationLoader.Context
import play.api.{ApplicationLoader, BuiltInComponentsFromContext, Mode}
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import router.Routes
import com.softwaremill.macwire._
import controllers.Assets
import uk.co.turingatemyhamster.shoppinglist.user.api.UserService
import scala.collection.immutable
import scala.concurrent.ExecutionContext
abstract class WebGateway(context: Context) extends BuiltInComponentsFromContext(context)
with I18nComponents
with AhcWSComponents
with LagomServiceClientComponents
{
override lazy val serviceInfo: ServiceInfo = ServiceInfo(
"web-ui",
Map(
"web-ui" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
)
)
override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
protected implicit lazy val playConfig = context.initialConfiguration
protected implicit lazy val playEnv = context.environment
override lazy val router: Routes = {
val prefix = "/"
wire[Routes]
}
lazy val userService = serviceClient.implement[UserService]
lazy val cApplication: controllers.Application = wire[controllers.Application]
lazy val assets: Assets = wire[Assets]
}
class WebGatewayLoader extends ApplicationLoader {
override def load(context: Context) = context.environment.mode match {
case Mode.Dev =>
new WebGateway(context) with LagomDevModeComponents {}.application
case _ =>
new WebGateway(context) {
override def serviceLocator = NoServiceLocator
}.application
}
}
开发者ID:drdozer,项目名称:shoppinglist,代码行数:55,代码来源:Loader.scala
示例9: ConsulServiceLocatorModule
//设置package包名称以及导入依赖的类
package com.lightbend.lagom.discovery.consul
import com.lightbend.lagom.javadsl.api.ServiceLocator
import play.api.{Configuration, Environment, Mode}
import play.api.inject.{Binding, Module}
import javax.inject.Singleton
import javax.inject.Inject
import javax.inject.Provider
import com.ecwid.consul.v1.ConsulClient
class ConsulServiceLocatorModule extends Module {
override def bindings(environment: Environment, configuration: Configuration): Seq[Binding[_]] =
if (environment.mode == Mode.Prod) Seq(
bind[ServiceLocator].to[ConsulServiceLocator].in[Singleton],
bind[ConsulConfig].to[ConsulConfig.ConsulConfigImpl],
bind[ConsulClient].toProvider[ConsulServiceLocatorModule.ConsulClientProvider]
)
else Seq.empty
}
object ConsulServiceLocatorModule {
private class ConsulClientProvider @Inject()(config: ConsulConfig) extends Provider[ConsulClient] {
override lazy val get: ConsulClient = new ConsulClient(config.agentHostname, config.agentPort)
}
}
开发者ID:jboner,项目名称:lagom-service-locator-consul,代码行数:30,代码来源:ConsulServiceLocatorModule.scala
示例10: MockedApplication
//设置package包名称以及导入依赖的类
import org.openqa.selenium.WebDriver
import play.api.test._
import play.api.{ApplicationLoader, Environment, Mode}
class MockedApplication
extends WithApplicationLoader(
new MockedApplicationLoader)
class MockedApplicationWithBrowser[W <: WebDriver]
extends WithBrowser[W](
app = new MockedApplicationLoader().load(
ApplicationLoader.createContext(
new Environment(
new java.io.File("."),
ApplicationLoader.getClass.getClassLoader,
Mode.Test))))
开发者ID:leanovate,项目名称:contoso-conference-manager,代码行数:17,代码来源:MockedApplication.scala
示例11: Frontend
//设置package包名称以及导入依赖的类
import be.yannickdeturck.lagomshopscala.item.api.ItemService
import be.yannickdeturck.lagomshopscala.order.api.OrderService
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo, ServiceLocator}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import com.lightbend.lagom.internal.client.CircuitBreakerMetricsProviderImpl
import com.lightbend.lagom.scaladsl.api.ServiceLocator.NoServiceLocator
import com.lightbend.lagom.scaladsl.broker.kafka.LagomKafkaClientComponents
import com.softwaremill.macwire._
import controllers.{Assets, DashboardController, ItemController, OrderController}
import play.api.ApplicationLoader.Context
import play.api.i18n.I18nComponents
import play.api.libs.ws.ahc.AhcWSComponents
import play.api.{Application, ApplicationLoader, BuiltInComponentsFromContext, Mode}
import router.Routes
import scala.collection.immutable
import scala.concurrent.ExecutionContext
abstract class Frontend(context: Context) extends BuiltInComponentsFromContext(context)
with I18nComponents
with AhcWSComponents
with LagomKafkaClientComponents
with LagomServiceClientComponents {
override lazy val serviceInfo: ServiceInfo = ServiceInfo(
"frontend",
Map(
"frontend" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*"))
)
)
override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
override lazy val router = {
val prefix = "/"
wire[Routes]
}
lazy val itemService: ItemService = serviceClient.implement[ItemService]
lazy val itemController: ItemController = wire[ItemController]
lazy val orderService: OrderService = serviceClient.implement[OrderService]
lazy val orderController: OrderController = wire[OrderController]
lazy val dashboardController: DashboardController = wire[DashboardController]
lazy val assets: Assets = wire[Assets]
}
class FrontendLoader extends ApplicationLoader {
override def load(context: Context): Application = context.environment.mode match {
case Mode.Dev =>
(new Frontend(context) with LagomDevModeComponents).application
case _ =>
new Frontend(context) {
override lazy val circuitBreakerMetricsProvider = new CircuitBreakerMetricsProviderImpl(actorSystem)
override def serviceLocator: ServiceLocator = NoServiceLocator
}.application
}
}
开发者ID:yannickdeturck,项目名称:lagom-shop-scala,代码行数:59,代码来源:Loader.scala
示例12: environment
//设置package包名称以及导入依赖的类
package components
import cassandra.{CassandraConnector, CassandraConnectionUri}
import com.datastax.driver.core.Session
import models.ProductModel
import play.api.inject.ApplicationLifecycle
import play.api.{Configuration, Environment, Mode}
import repositories.{Repository, ProductsRepository}
import scala.concurrent.Future
trait CassandraRepositoryComponents {
// These will be filled by Play's built-in components; should be `def` to avoid initialization problems
def environment: Environment
def configuration: Configuration
def applicationLifecycle: ApplicationLifecycle
lazy private val cassandraSession: Session = {
val uriString = environment.mode match {
case Mode.Prod => "cassandra://localhost:9042/prod"
case _ => "cassandra://localhost:9042/test"
}
val session: Session = CassandraConnector.createSessionAndInitKeyspace(
CassandraConnectionUri(uriString)
)
// Shutdown the client when the app is stopped or reloaded
applicationLifecycle.addStopHook(() => Future.successful(session.close()))
session
}
lazy val productsRepository: Repository[ProductModel, Int] = {
new ProductsRepository(cassandraSession)
}
}
开发者ID:manuelkiessling,项目名称:play2-compiletime-cassandra-di,代码行数:35,代码来源:CassandraRepositoryComponents.scala
示例13: IntegrationSpec
//设置package包名称以及导入依赖的类
import java.io.File
import cassandra.{CassandraConnector, CassandraConnectionUri}
import org.scalatest.BeforeAndAfter
import org.scalatestplus.play._
import play.api
import play.api.{Mode, Environment, ApplicationLoader}
class IntegrationSpec extends PlaySpec with OneBrowserPerSuite with OneServerPerSuite with HtmlUnitFactory with BeforeAndAfter {
before {
val uri = CassandraConnectionUri("cassandra://localhost:9042/test")
val session = CassandraConnector.createSessionAndInitKeyspace(uri)
val query = "INSERT INTO products (id, name) VALUES (1, 'Chair');"
session.execute(query)
session.close()
}
override implicit lazy val app: api.Application =
new AppLoader().load(
ApplicationLoader.createContext(
new Environment(
new File("."), ApplicationLoader.getClass.getClassLoader, Mode.Test)
)
)
"Application" should {
"work from within a browser and tell us about the first product" in {
go to "http://localhost:" + port
pageSource must include ("Your new application is ready. The name of product #1 is Chair.")
}
}
}
开发者ID:manuelkiessling,项目名称:play2-compiletime-cassandra-di,代码行数:36,代码来源:IntegrationSpec.scala
示例14: MockProductsRepository
//设置package包名称以及导入依赖的类
import java.io.File
import models.ProductModel
import play.api
import play.api.{Mode, Environment, ApplicationLoader}
import play.api.ApplicationLoader.Context
import play.api.test._
import play.api.test.Helpers._
import org.scalatestplus.play._
import repositories.Repository
class MockProductsRepository extends Repository[ProductModel, Int] {
override def getOneById(id: Int): ProductModel = {
ProductModel(1, "Mocked Chair")
}
}
class FakeApplicationComponents(context: Context) extends AppComponents(context) {
override lazy val productsRepository = new MockProductsRepository()
}
class FakeAppLoader extends ApplicationLoader {
override def load(context: Context): api.Application =
new FakeApplicationComponents(context).application
}
class ApplicationSpec extends PlaySpec with OneAppPerSuite {
override implicit lazy val app: api.Application = {
val appLoader = new FakeAppLoader
appLoader.load(
ApplicationLoader.createContext(
new Environment(
new File("."), ApplicationLoader.getClass.getClassLoader, Mode.Test)
)
)
}
"Application" should {
"send 404 on a bad request" in {
val Some(wrongRoute) = route(FakeRequest(GET, "/boum"))
status(wrongRoute) mustBe NOT_FOUND
}
"render the index page and tell us about the first product" in {
val Some(home) = route(FakeRequest(GET, "/"))
status(home) mustBe OK
contentType(home) mustBe Some("text/html")
contentAsString(home) must include ("Your new application is ready. The name of product #1 is Mocked Chair.")
}
}
}
开发者ID:manuelkiessling,项目名称:play2-compiletime-cassandra-di,代码行数:56,代码来源:ApplicationSpec.scala
示例15: WebGateway
//设置package包名称以及导入依赖的类
import com.example.counter.api.CounterService
import com.lightbend.lagom.scaladsl.api.{ServiceAcl, ServiceInfo}
import com.lightbend.lagom.scaladsl.client.LagomServiceClientComponents
import com.lightbend.lagom.scaladsl.devmode.LagomDevModeComponents
import play.api.{ApplicationLoader, BuiltInComponentsFromContext, Mode}
import play.api.ApplicationLoader.Context
import play.api.i18n.{I18nComponents, MessagesApi}
import play.api.libs.ws.ahc.AhcWSComponents
import com.softwaremill.macwire._
import controllers.{CounterController, HomeController}
import router.Routes
import scala.collection.immutable
import scala.concurrent.ExecutionContext
abstract class WebGateway(context: Context) extends BuiltInComponentsFromContext(context)
with I18nComponents with AhcWSComponents with LagomServiceClientComponents {
override lazy val serviceInfo = ServiceInfo(
"front-end",
Map("front-end" -> immutable.Seq(ServiceAcl.forPathRegex("(?!/api/).*")))
)
override implicit lazy val executionContext: ExecutionContext = actorSystem.dispatcher
implicit lazy val message: MessagesApi = messagesApi
override lazy val router = {
val prefix = "/"
wire[Routes]
}
lazy val counterService = serviceClient.implement[CounterService]
lazy val home = wire[HomeController]
lazy val counter = wire[CounterController]
}
class WebGatewayLoader extends ApplicationLoader {
override def load(context: Context) = context.environment.mode match {
case Mode.Dev => (new WebGateway(context) with LagomDevModeComponents).application
case _ => throw new Exception("Not ready for deployment yet.")
}
}
开发者ID:namelos,项目名称:lagom-spike,代码行数:43,代码来源:Loader.scala
示例16: SecurityFilterSpec
//设置package包名称以及导入依赖的类
package org.zalando.zhewbacca
import play.api.inject._
import play.api.inject.guice.GuiceApplicationBuilder
import play.api.mvc.Results._
import play.api.mvc._
import play.api.test.{FakeRequest, PlaySpecification}
import play.api.{Application, Mode}
class SecurityFilterSpec extends PlaySpecification with BodyParsers {
val TestTokenInfo = TokenInfo("", Scope.Empty, "token type", "user uid")
val routes: PartialFunction[(String, String), Handler] = {
// test action returning action type. Shows the usage and makes it possible to test basic behaviour
// security rules described in 'security_filter.conf' file
case ("GET", "/") => Action { request =>
import TokenInfoConverter._
Ok(request.tokenInfo.tokenType)
}
case ("GET", "/unprotected") => Action {
Ok
}
}
def appWithRoutes: Application = new GuiceApplicationBuilder()
.in(Mode.Test)
.bindings(bind[AuthProvider] to new AlwaysPassAuthProvider(TestTokenInfo))
.routes(routes)
.configure(
"play.http.filters" -> "org.zalando.zhewbacca.TestingFilters",
"authorisation.rules.file" -> "security_filter.conf"
)
.build
"SecurityFilter" should {
"allow protected inner action to access token info" in {
val response = route(appWithRoutes, FakeRequest(GET, "/")).get
status(response) must beEqualTo(OK)
contentAsString(response) must beEqualTo(TestTokenInfo.tokenType)
}
"deny an access when there is no security rule for the reguest is given" in {
val response = route(appWithRoutes, FakeRequest(GET, "/unprotected-by-mistake")).get
status(response) must beEqualTo(FORBIDDEN)
}
}
}
开发者ID:zalando-incubator,项目名称:play-zhewbacca,代码行数:53,代码来源:SecurityFilterSpec.scala
示例17: channelByPath
//设置package包名称以及导入依赖的类
package de.welt.contentapi.client.services.configuration
import javax.inject.{Inject, Singleton}
import de.welt.contentapi.core.models.config
import de.welt.contentapi.core.models.config.{Channel, ChannelData, ChannelId, Env}
import de.welt.contentapi.client.services.contentapi.LegacySectionService
import de.welt.contentapi.client.services.s3.S3
import de.welt.contentapi.core.traits.Loggable
import play.api.cache.CacheApi
import play.api.libs.json.{JsError, JsSuccess, Json}
import play.api.{Environment, Mode}
import scala.concurrent.duration._
trait SectionConfigurationService {
def channelByPath(id: ChannelId)(implicit env: Env): Option[Channel]
}
@Singleton
class SectionConfigurationServiceImpl @Inject()(funkConfig: ContentClientConfig,
s3: S3,
environment: Environment,
legacySectionService: LegacySectionService,
cache: CacheApi)
extends SectionConfigurationService with Loggable {
override def channelByPath(id: ChannelId)(implicit env: Env): Option[Channel] = {
root.findByPath(id.path)
}
private def objectKeyForEnv(env: Env) = environment.mode match {
case Mode.Prod ? s"janus2/prod/${env.toString}/config.json"
case _ ? s"janus2/dev/${env.toString}/config.json"
}
private[configuration] def root(implicit env: Env): Channel = cache.getOrElse(env.toString, 10.minutes) {
import config.WithChildrenReads._
val maybeData: Option[String] = s3.get(funkConfig.aws.s3.janus.bucket, objectKeyForEnv(env))
maybeData
.map { data ? Json.parse(data).validate[Channel] }
.flatMap {
case JsSuccess(v, _) ?
Some(v)
case [email protected](_) ?
log.warn(err.toString)
None
}.getOrElse {
log.warn("No data found in s3 bucket.")
throw new IllegalStateException("no channel data")
}
}
}
开发者ID:WeltN24-public,项目名称:WeltContentApiClient,代码行数:59,代码来源:SectionConfigurationService.scala
示例18: channelByPath
//设置package包名称以及导入依赖的类
package de.welt.services.configuration
import javax.inject.{Inject, Singleton}
import de.welt.models.config
import de.welt.models.config.{Channel, ChannelData, ChannelId, Env}
import de.welt.services.contentapi.LegacySectionService
import de.welt.services.s3.S3
import de.welt.traits.Loggable
import play.api.cache.CacheApi
import play.api.libs.json.{JsError, JsSuccess, Json}
import play.api.{Environment, Mode}
import scala.concurrent.duration._
trait SectionConfigurationService {
def channelByPath(id: ChannelId)(implicit env: Env): Option[Channel]
}
@Singleton
class SectionConfigurationServiceImpl @Inject()(funkConfig: ContentClientConfig,
s3: S3,
environment: Environment,
legacySectionService: LegacySectionService,
cache: CacheApi)
extends SectionConfigurationService with Loggable {
override def channelByPath(id: ChannelId)(implicit env: Env): Option[Channel] = {
root.findByPath(id.path)
}
private def objectKeyForEnv(env: Env) = environment.mode match {
case Mode.Prod ? s"janus2/prod/${env.toString}/config.json"
case _ ? s"janus2/dev/${env.toString}/config.json"
}
private[configuration] def root(implicit env: Env): Channel = cache.getOrElse(env.toString, 10.minutes) {
import config.WithChildrenReads._
val maybeData: Option[String] = s3.get(funkConfig.aws.s3.janus.bucket, objectKeyForEnv(env))
maybeData
.map { data ? Json.parse(data).validate[Channel] }
.flatMap {
case JsSuccess(v, _) ?
Some(v)
case [email protected](_) ?
log.warn(err.toString)
None
}.getOrElse {
log.warn("No data found in s3 bucket.")
throw new IllegalStateException("no channel data")
}
}
}
开发者ID:WeltN24-public,项目名称:WeltContentApiClient,代码行数:59,代码来源:SectionConfigurationService.scala
示例19: ApplicationInitializer
//设置package包名称以及导入依赖的类
package cores.task.internal
import play.api.{Application, ApplicationLoader, Environment, Mode}
private[task] object ApplicationInitializer {
def initialize(): Application = {
val environment = Environment(new java.io.File("."), this.getClass.getClassLoader, mode)
val context = ApplicationLoader.createContext(environment)
val loader = ApplicationLoader(context)
loader.load(context)
}
private def mode: Mode.Mode = {
System.getProperty("play.mode") match {
case "Prod" => Mode.Prod
case _ => Mode.Dev
}
}
}
开发者ID:tmknom,项目名称:scala-ddd,代码行数:20,代码来源:ApplicationInitializer.scala
示例20: LeakSpec
//设置package包名称以及导入依赖的类
import db.FooDb
import org.scalatest.concurrent.{IntegrationPatience, ScalaFutures}
import org.scalatestplus.play._
import play.api.Mode
import play.api.inject.guice.GuiceApplicationBuilder
class LeakSpec
extends PlaySpec
with OneAppPerSuite
with ScalaFutures
with IntegrationPatience {
override lazy val app = new GuiceApplicationBuilder()
.in(Mode.Test)
.build
"run test" in {
val fooDb = app.injector.instanceOf[FooDb]
whenReady(fooDb.findAll()) { result =>
result mustBe a[Seq[_]]
}
}
}
开发者ID:rfuerst87,项目名称:slick-leak-demo,代码行数:24,代码来源:LeakSpec.scala
注:本文中的play.api.Mode类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论