This file contains hidden or 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
case class User(name:String) | |
trait MyApi { | |
// Binding http path parameters (e.g., :name) to method arguments | |
@Endpoint(method = HttpMethod.GET, path = "/user/:name") | |
def getUser(name: String): User = User(name) | |
} |
This file contains hidden or 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
trait DbService { | |
private val connectionPool = bind[ConnectionPool] | |
.onStart { dbConfig: DbConfig => startConnectionPool(dbConfig) } | |
.onShutdown { _.close } | |
def query(sql:String) = { connectionPool.execute(sql) ... } | |
} |
This file contains hidden or 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
import wvlet.airframe._ | |
trait MyApp { | |
private val threadPool = bind[ThreadPool] | |
private val dbService = bind[DbService] | |
... | |
threadPool.submit(dbService.query("select ...")) | |
} |
This file contains hidden or 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
import wvlet.airframe._ | |
// Read configurations from a YAML file | |
val yaml = readConfig("config.yml") | |
// Configure Application | |
val d = newDesign | |
.bind[ServiceConfig].toInstance(new ServiceConfig(yaml.get(...), yaml.get(..)) | |
.bind[WebAppConfig].toInstance(new WebAppConfig(...)) | |
// Initialize Services |
This file contains hidden or 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
// New Services | |
class WebApp(webAppConfig:WebAppConfig, component:WebComponent) | |
class WebComponent(service:Service) | |
// Pack configuration set in a class | |
case class ConfigSet(serviceConfig:ServiceConfig, webAppConfig:WebAppConfig) | |
// Read configurations from a YAML file | |
def readConfig: ConfigSet = { | |
val yaml = readConfig("config.yml") |
This file contains hidden or 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
case class ServiceConfig(host:String, port:Int) | |
class Service(config:ServiceConfig) { | |
// ... | |
} | |
// Building a service instance | |
val config = new ServiceConfig("localhost", "8080") | |
val service = new Service(config) |
This file contains hidden or 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
logger.resetHandler(new LogRotationHandler( | |
fileName = "your-app.log", | |
maxNumberOfFiles = 100, // rotate up to 100 log files | |
maxSizeInBytes = 100 * 1024 * 1024 // 100MB | |
AppLogFormatter // Any log formatter you like | |
)) |
This file contains hidden or 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
import org.scalatest._ | |
import wvlet.log.LogFormatter.SourceCodeLogFormatter | |
trait Spec extends WordSpec with Matchers with LogSupport { | |
override def run(testName: Option[String], args: Args): Status = { | |
// Add source code location to the debug logs | |
Logger.setDefaultFormatter(SourceCodeLogFormatter) | |
// Periodically scan log level file | |
Logger.scheduleLogLevelScan |
This file contains hidden or 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
import org.slf4j.Logger | |
import org.slf4j.LoggerFactory | |
object MyApp { | |
val logger = LoggerFactory.getLogger(classOf[HelloWorld]) | |
logger.info("Hello World") | |
} |
This file contains hidden or 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
import wvlet.log.LogSupport | |
object MyApp extends LogSupport { | |
info("Hello airframe-log!") | |
warn("This is a warning message") | |
debug("debug messsages will not be shown by default") | |
} |