aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jakob@driver.xyz>2018-10-11 14:19:28 -0700
committerJakob Odersky <jakob@driver.xyz>2018-10-12 13:13:17 -0700
commita43556851bf986b81351fc9f1ae5ba51bf21dc47 (patch)
treeb5863203cb94b510ec4e4c2c611dd15317cbd5b8
parent03ed05c0fcb948237d66f032c4e530b2349404b9 (diff)
downloaddriver-core-master.tar.gz
driver-core-master.tar.bz2
driver-core-master.zip
Add an example to the README and a standalone application templateHEADv2.0.0-M5masterjo/example
-rw-r--r--README.md26
-rw-r--r--core-init/src/main/scala/xyz/driver/core/init/BuildInfoReflection.scala2
-rw-r--r--core-init/src/main/scala/xyz/driver/core/init/HttpApi.scala2
-rw-r--r--documentation/example/.gitignore1
-rw-r--r--documentation/example/build.sbt6
-rw-r--r--documentation/example/project/build.properties1
-rw-r--r--documentation/example/project/plugins.sbt1
-rw-r--r--documentation/example/src/main/scala/example/Main.scala21
8 files changed, 57 insertions, 3 deletions
diff --git a/README.md b/README.md
index ec0050a..9edbfe1 100644
--- a/README.md
+++ b/README.md
@@ -82,7 +82,31 @@ libraries used are:
## Example Usage
-*TODO*
+The following implements a simple key-value store that uses object
+storage ("buckets") when running in the cloud and a local filesystem
+when running on a development machine.
+```scala
+import xyz.driver.core.init
+
+object Main extends init.SimpleHttpApp {
+
+ lazy val fs = storage("data")
+
+ override def applicationRoute = path("data" / Segment) { key =>
+ post {
+ entity(as[Array[Byte]]) { value =>
+ complete(fs.uploadContent(key, value))
+ }
+ } ~ get {
+ rejectEmptyResponse{
+ complete(fs.content(key))
+ }
+ }
+ }
+
+}
+```
+See [this example project](documentation/example) for a more details.
## Building
diff --git a/core-init/src/main/scala/xyz/driver/core/init/BuildInfoReflection.scala b/core-init/src/main/scala/xyz/driver/core/init/BuildInfoReflection.scala
index 0e53085..a8bee9b 100644
--- a/core-init/src/main/scala/xyz/driver/core/init/BuildInfoReflection.scala
+++ b/core-init/src/main/scala/xyz/driver/core/init/BuildInfoReflection.scala
@@ -10,7 +10,7 @@ private[init] object BuildInfoReflection {
final val BuildInfoName = "xyz.driver.BuildInfo"
- lazy val name: String = get[String]("name")
+ lazy val name: String = find[String]("name").getOrElse("unknown")
lazy val version: Option[String] = find[String]("version")
/** Lookup a given field in the build configuration. This field is required to exist. */
diff --git a/core-init/src/main/scala/xyz/driver/core/init/HttpApi.scala b/core-init/src/main/scala/xyz/driver/core/init/HttpApi.scala
index 81428bf..2570cb3 100644
--- a/core-init/src/main/scala/xyz/driver/core/init/HttpApi.scala
+++ b/core-init/src/main/scala/xyz/driver/core/init/HttpApi.scala
@@ -27,7 +27,7 @@ trait HttpApi extends CloudServices with Directives with SprayJsonSupport { self
/** Classes with Swagger annotations.
* @group hooks
*/
- def swaggerRouteClasses: Set[Class[_]]
+ def swaggerRouteClasses: Set[Class[_]] = Set(self.getClass)
private val healthRoute = path("health") {
complete(Map("status" -> "good").toJson)
diff --git a/documentation/example/.gitignore b/documentation/example/.gitignore
new file mode 100644
index 0000000..2157ef4
--- /dev/null
+++ b/documentation/example/.gitignore
@@ -0,0 +1 @@
+.data-*
diff --git a/documentation/example/build.sbt b/documentation/example/build.sbt
new file mode 100644
index 0000000..d2bd592
--- /dev/null
+++ b/documentation/example/build.sbt
@@ -0,0 +1,6 @@
+lazy val `example-app` = project
+ .in(file("."))
+ .enablePlugins(ServicePlugin)
+ .settings(
+ libraryDependencies += "xyz.driver" %% "core-init" % "2.0.0-M5"
+ )
diff --git a/documentation/example/project/build.properties b/documentation/example/project/build.properties
new file mode 100644
index 0000000..0cd8b07
--- /dev/null
+++ b/documentation/example/project/build.properties
@@ -0,0 +1 @@
+sbt.version=1.2.3
diff --git a/documentation/example/project/plugins.sbt b/documentation/example/project/plugins.sbt
new file mode 100644
index 0000000..53be881
--- /dev/null
+++ b/documentation/example/project/plugins.sbt
@@ -0,0 +1 @@
+addSbtPlugin("xyz.driver" % "sbt-settings" % "2.0.12")
diff --git a/documentation/example/src/main/scala/example/Main.scala b/documentation/example/src/main/scala/example/Main.scala
new file mode 100644
index 0000000..2548f79
--- /dev/null
+++ b/documentation/example/src/main/scala/example/Main.scala
@@ -0,0 +1,21 @@
+package example
+
+import xyz.driver.core.init
+
+object Main extends init.SimpleHttpApp {
+
+ lazy val fs = this.storage("data")
+
+ override def applicationRoute = path("data" / Segment) { key =>
+ post {
+ entity(as[Array[Byte]]) { value =>
+ complete(fs.uploadContent(key, value))
+ }
+ } ~ get {
+ rejectEmptyResponse{
+ complete(fs.content(key))
+ }
+ }
+ }
+
+}