feat: split up into seperate modules before it gets too tangled up

This commit is contained in:
silver 2023-06-04 12:17:16 +01:00
parent 82ce0a864f
commit 9b52052add
4 changed files with 117 additions and 117 deletions

View file

@ -1,6 +1,8 @@
pub mod methods;
use dotenv::dotenv;
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
use sqlx::{Error, Pool, Sqlite};
use std::env;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
@ -41,3 +43,39 @@ pub fn get_now() -> i64 {
0
}
}
#[derive(Clone)]
pub struct State {
pub db: Pool<Sqlite>,
pub config: Config,
}
#[derive(Debug, Clone)]
pub struct Config {
ldap_host: String,
pub database: String,
pub host_port: String,
}
pub fn get_config() -> Config {
dotenv().ok();
// reasonable defaults
let mut config = Config {
ldap_host: "".to_string(),
database: "database.db".to_string(),
host_port: "127.0.0.1:8087".to_string(),
};
if let Ok(x) = env::var("LDAP_HOST") {
config.ldap_host = x.trim().to_string();
}
if let Ok(x) = env::var("DATABASE") {
config.database = x.trim().to_string();
}
if let Ok(x) = env::var("HOST_PORT") {
config.host_port = x.trim().to_string();
}
config
}