Browse Source

add Gotham web framework for Rust (#3428)

* add Gotham web framework for Rust

* remove unneeded line
Nikolay Kim 7 years ago
parent
commit
68b04c2fdf

+ 1 - 0
.travis.yml

@@ -188,6 +188,7 @@ env:
      - "TESTDIR=Rust/tokio-minihttp"
      - "TESTDIR=Rust/rouille"
      - "TESTDIR=Rust/actix"
+     - "TESTDIR=Rust/gotham"
      - "TESTDIR=Scala/akka-http"
      - "TESTDIR=Scala/blaze"
      - "TESTDIR=Scala/colossus"

+ 12 - 0
frameworks/Rust/gotham/Cargo.toml

@@ -0,0 +1,12 @@
+[package]
+name = "gotham-bench"
+version = "0.1.0"
+
+[dependencies]
+futures = "0.1"
+hyper = "0.11"
+gotham = "0.2"
+serde = "1.0"
+serde_json = "1.0"
+serde_derive = "1.0"
+mime = "0.3"

+ 22 - 0
frameworks/Rust/gotham/benchmark_config.json

@@ -0,0 +1,22 @@
+{
+  "framework": "gotham",
+  "tests": [{
+    "default": {
+      "json_url": "/json",
+      "plaintext_url": "/plaintext",
+      "port": 8080,
+      "approach": "Realistic",
+      "classification": "Micro",
+      "database": "Postgres",
+      "framework": "gotham",
+      "language": "Rust",
+      "orm": "Raw",
+      "platform": "Rust",
+      "webserver": "Hyper",
+      "os": "Linux",
+      "database_os": "Linux",
+      "display_name": "Gotham",
+      "notes": ""
+    }
+  }]
+}

+ 8 - 0
frameworks/Rust/gotham/gotham.dockerfile

@@ -0,0 +1,8 @@
+FROM tfb/rust:latest
+
+COPY ./ ./
+
+RUN cargo clean
+RUN RUSTFLAGS="-C target-cpu=native" cargo build --release
+
+CMD ./target/release/gotham-bench

+ 61 - 0
frameworks/Rust/gotham/src/main.rs

@@ -0,0 +1,61 @@
+extern crate futures;
+extern crate gotham;
+extern crate hyper;
+extern crate mime;
+extern crate serde;
+extern crate serde_json;
+#[macro_use] extern crate serde_derive;
+
+use hyper::{header, Response, StatusCode};
+use gotham::http::response::create_response;
+use gotham::state::State;
+use gotham::router::Router;
+use gotham::router::builder::*;
+
+
+#[derive(Serialize, Deserialize)]
+pub struct Message {
+    pub message: &'static str,
+}
+
+
+pub fn json(state: State) -> (State, Response) {
+    let message = Message {
+        message: "Hello, World!"
+    };
+    let body = serde_json::to_string(&message).unwrap();
+
+    let mut res = create_response(
+        &state,
+        StatusCode::Ok,
+        Some((body.into_bytes(), mime::APPLICATION_JSON)),
+    );
+    res.headers_mut().set(header::Server::new("Gotham"));
+
+    (state, res)
+}
+
+
+pub fn plaintext(state: State) -> (State, Response) {
+    let mut res = create_response(
+        &state,
+        StatusCode::Ok,
+        Some((String::from("Hello, World!").into_bytes(), mime::TEXT_PLAIN)),
+    );
+    res.headers_mut().set(header::Server::new("Gotham"));
+
+    (state, res)
+}
+
+fn router() -> Router {
+    build_simple_router(|route| {
+        route.get("/plaintext").to(plaintext);
+        route.get("/json").to(json);
+    })
+}
+
+pub fn main() {
+    let addr = "0.0.0.0:8080";
+    println!("Listening for requests at http://{}", addr);
+    gotham::start(addr, router())
+}