2019-07-15 01:15:25 +02:00
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2018-11-26 07:13:22 +01:00
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct Configuration {
|
|
|
|
pub address: String,
|
2019-07-12 07:28:46 +02:00
|
|
|
pub domain: String,
|
2018-11-26 07:13:22 +01:00
|
|
|
pub threads: usize,
|
|
|
|
pub db_path: String,
|
|
|
|
pub maximum_request: usize,
|
|
|
|
// db type later
|
2019-04-18 03:28:33 +02:00
|
|
|
pub secure_cookies: bool,
|
2018-11-26 07:13:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Configuration {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Configuration {
|
|
|
|
address: String::from("127.0.0.1:8080"),
|
2019-07-12 07:28:46 +02:00
|
|
|
domain: String::from("127.0.0.1"),
|
2018-11-26 07:13:22 +01:00
|
|
|
threads: 8,
|
|
|
|
db_path: String::from(""),
|
|
|
|
maximum_request: 262144, // 256k
|
2019-04-18 03:28:33 +02:00
|
|
|
// log type
|
|
|
|
// log path
|
2019-07-12 07:28:46 +02:00
|
|
|
// TODO: default true in prd
|
|
|
|
secure_cookies: false,
|
2018-11-26 07:13:22 +01:00
|
|
|
}
|
|
|
|
}
|
2019-07-15 01:15:25 +02:00
|
|
|
|
|
|
|
pub fn update_db_path(&mut self, p: &PathBuf) {
|
|
|
|
match p.to_str() {
|
|
|
|
Some(p) => self.db_path = p.to_string(),
|
|
|
|
None => {
|
|
|
|
error!("Invalid DB path supplied");
|
|
|
|
std::process::exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-26 07:13:22 +01:00
|
|
|
}
|