aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/api_server.rs10
-rw-r--r--rust/src/bin/fatcat-iron.rs31
-rw-r--r--rust/src/lib.rs28
3 files changed, 38 insertions, 31 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index 3da38724..3e2e6c9c 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -7,12 +7,12 @@ use futures::{self, Future};
use std::collections::HashMap;
-use ConnectionPool;
use self::models::*;
+use ConnectionPool;
use diesel;
-use r2d2;
use diesel::prelude::*;
use iron_diesel_middleware::DieselPooledConnection;
+use r2d2;
use r2d2_diesel::ConnectionManager;
use swagger;
@@ -43,7 +43,7 @@ impl Api for Server {
let conn = self.db_pool.get().expect("db_pool error");
let c: i64 = container_rev.count().first(&*conn).expect("DB Error");
println!("container count: {}", c);
- let ce = ContainerEntity{
+ let ce = ContainerEntity {
issn: None,
publisher: Some("Hello!".into()),
parent: None,
@@ -54,7 +54,9 @@ impl Api for Server {
redirect: None,
editgroup: None,
};
- Box::new(futures::done(Ok(ContainerIdGetResponse::FetchASingleContainerById(ce))))
+ Box::new(futures::done(Ok(
+ ContainerIdGetResponse::FetchASingleContainerById(ce),
+ )))
}
fn container_lookup_get(
diff --git a/rust/src/bin/fatcat-iron.rs b/rust/src/bin/fatcat-iron.rs
index d89a9c53..e0705787 100644
--- a/rust/src/bin/fatcat-iron.rs
+++ b/rust/src/bin/fatcat-iron.rs
@@ -2,28 +2,30 @@
extern crate chrono;
extern crate clap;
+extern crate diesel;
+extern crate dotenv;
extern crate fatcat;
extern crate fatcat_api;
extern crate futures;
-extern crate dotenv;
-extern crate diesel;
-extern crate iron_diesel_middleware;
extern crate iron;
+extern crate iron_diesel_middleware;
extern crate iron_slog;
extern crate swagger;
-#[macro_use] extern crate error_chain;
-#[macro_use] extern crate slog;
-extern crate slog_term;
+#[macro_use]
+extern crate error_chain;
+#[macro_use]
+extern crate slog;
extern crate slog_async;
+extern crate slog_term;
-use slog::{Drain, Logger};
-use iron_slog::{LoggerMiddleware, DefaultLogFormatter};
use clap::{App, Arg};
-use iron::{Chain, Iron};
-use swagger::auth::AllowAllMiddleware;
use dotenv::dotenv;
-use std::env;
+use iron::{Chain, Iron};
use iron_diesel_middleware::{DieselMiddleware, DieselPooledConnection, DieselReqExt};
+use iron_slog::{DefaultLogFormatter, LoggerMiddleware};
+use slog::{Drain, Logger};
+use std::env;
+use swagger::auth::AllowAllMiddleware;
/// Create custom server, wire it to the autogenerated router,
/// and pass it to the web server.
@@ -36,7 +38,6 @@ fn main() {
)
.get_matches();
-
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::CompactFormat::new(decorator).build().fuse();
let drain = slog_async::Async::new(drain).build().fuse();
@@ -46,13 +47,13 @@ fn main() {
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
- let diesel_middleware: DieselMiddleware<diesel::pg::PgConnection> = DieselMiddleware::new(&database_url).unwrap();
+ let diesel_middleware: DieselMiddleware<diesel::pg::PgConnection> =
+ DieselMiddleware::new(&database_url).unwrap();
let server = fatcat::server().unwrap();
let router = fatcat_api::router(server);
- let mut chain = Chain::new(
- LoggerMiddleware::new(router, logger, formatter ));
+ let mut chain = Chain::new(LoggerMiddleware::new(router, logger, formatter));
chain.link_before(fatcat_api::server::ExtractAuthData);
// add authentication middlewares into the chain here
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index c1336561..b8f2be88 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -1,19 +1,22 @@
#[macro_use]
extern crate fatcat_api;
extern crate chrono;
-#[macro_use] extern crate diesel;
-extern crate iron_diesel_middleware;
+#[macro_use]
+extern crate diesel;
extern crate dotenv;
extern crate futures;
-#[macro_use] extern crate hyper;
+extern crate iron_diesel_middleware;
+#[macro_use]
+extern crate hyper;
extern crate swagger;
-#[macro_use] extern crate error_chain;
+#[macro_use]
+extern crate error_chain;
extern crate iron;
extern crate r2d2;
extern crate r2d2_diesel;
-pub mod database_schema;
pub mod api_server;
+pub mod database_schema;
mod errors {
error_chain!{}
@@ -23,10 +26,10 @@ pub use self::errors::*;
use diesel::pg::PgConnection;
use diesel::prelude::*;
use dotenv::dotenv;
-use std::env;
-use iron::{Request, Response};
use iron::middleware::AfterMiddleware;
+use iron::{Request, Response};
use r2d2_diesel::ConnectionManager;
+use std::env;
pub type ConnectionPool = r2d2::Pool<r2d2_diesel::ConnectionManager<diesel::pg::PgConnection>>;
@@ -42,10 +45,10 @@ pub fn server() -> Result<api_server::Server> {
dotenv().ok();
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let manager = ConnectionManager::<PgConnection>::new(database_url);
- let pool = r2d2::Pool::builder().build(manager).expect("Failed to create database pool.");
- Ok(api_server::Server {
- db_pool: pool,
- })
+ let pool = r2d2::Pool::builder()
+ .build(manager)
+ .expect("Failed to create database pool.");
+ Ok(api_server::Server { db_pool: pool })
}
/// HTTP header middleware
@@ -55,7 +58,8 @@ pub struct XClacksOverheadMiddleware;
impl AfterMiddleware for XClacksOverheadMiddleware {
fn after(&self, _req: &mut Request, mut res: Response) -> iron::IronResult<Response> {
- res.headers.set(XClacksOverhead("GNU aaronsw, jpb".to_owned()));
+ res.headers
+ .set(XClacksOverhead("GNU aaronsw, jpb".to_owned()));
Ok(res)
}
}