Set of administration tools for 42l's infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
821 B

use diesel::pg::PgConnection;
use diesel::prelude::*;
use std::fs::File;
use std::io::Read;
lazy_static! {
pub static ref CONFIG: Config = Config::init();
}
#[derive(Debug, Deserialize)]
pub struct Config {
pub database_url: String,
pub mail_logs_path: String,
pub mail_storage_path: String,
pub export_lists_path: String,
}
impl Config {
pub fn init() -> Self {
let mut conffile = File::open("config.toml").expect("Config file not found");
let mut confstr = String::new();
conffile
.read_to_string(&mut confstr)
.expect("Couldn't read config to string");
toml::from_str(&confstr).unwrap()
}
}
pub fn establish_connection() -> PgConnection {
PgConnection::establish(&CONFIG.database_url).expect("Error connecting to database")
}