blob: c1c42f01185f2af598ad57ddfd91084bbe328631 (
plain) (
tree)
|
|
use crate::constants::DEFAULT_CONFIG;
use crate::result::Result;
use serde::Deserialize;
use std::env::var;
use std::fs::File;
use std::io::prelude::*;
use std::net::SocketAddr;
use toml::from_str;
#[derive(Debug, Clone, Deserialize)]
pub struct Config {
pub db_url: String,
pub img_root: String,
pub bind_addr: SocketAddr,
}
impl Config {
pub fn from_toml() -> Result<Self> {
let path = var("DICHROISM_CONFIG").unwrap_or_else(|_| String::from(DEFAULT_CONFIG));
let mut config = String::new();
File::open(path)?.read_to_string(&mut config)?;
Ok(from_str(&config)?)
}
}
|