diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..7798967 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,22 @@ +use once_cell::sync::Lazy; +use std::{env::var, error::Error, net::SocketAddr}; + +pub static INSTANCE: Lazy<AppConfig> = + Lazy::new(|| AppConfig::from_env().expect("Error loading config")); + +#[derive(Clone, Debug)] +pub struct AppConfig { + pub addr: SocketAddr, + pub db_uri: String, +} + +impl AppConfig { + pub fn from_env() -> Result<Self, Box<dyn Error>> { + let new = Self { + addr: var("TWINH_ADDR")?.parse()?, + db_uri: var("TWINH_DB_URI")?, + }; + + Ok(new) + } +} |