summaryrefslogblamecommitdiff
path: root/src/config.rs
blob: 7798967120163ad67a6784fc2807d3d1d3f1d48e (plain) (tree)





















                                                                       
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)
    }
}