feat: split up into seperate modules before it gets too tangled up
This commit is contained in:
parent
82ce0a864f
commit
9b52052add
4 changed files with 117 additions and 117 deletions
40
src/lib.rs
40
src/lib.rs
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue