aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/lib.rs
blob: fbff6ab218b72cd62f780681626b30a2b6b17f62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#[macro_use]
extern crate fatcat_api;
extern crate chrono;
extern crate diesel;
extern crate dotenv;
extern crate futures;
extern crate hyper;
extern crate swagger;
#[macro_use]
extern crate error_chain;

pub mod api_server;

mod errors {
    error_chain!{}
}

pub use self::errors::*;
use diesel::pg::PgConnection;
use diesel::prelude::*;
use dotenv::dotenv;
use std::env;

pub fn establish_connection() -> PgConnection {
    dotenv().ok();

    let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
    PgConnection::establish(&database_url).expect(&format!("Error connecting to {}", database_url))
}

/// Instantiate a new server.
pub fn server() -> Result<api_server::Server> {
    Ok(api_server::Server {})
}