summaryrefslogblamecommitdiff
path: root/src/config.rs
blob: b3c9715cd3a000514cf8c187c370176843c91770 (plain) (tree)
1
2
3
4


                                                   
                                             

















                                                                       
use once_cell::sync::Lazy;
use std::{env::var, error::Error, net::SocketAddr};

pub static CONFIG_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)
    }
}