1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// lib.rs
// commenting tool related functions are implemented here

use std::collections::HashMap;
use lazy_static::*;
use config::{Config, File, FileFormat};

mod db;
pub mod log;
pub mod models;
pub mod filters;
pub mod handlers;
pub mod utils;
pub mod comment_server;

// Initialize: templates and settings
lazy_static!{
    static ref SETTINGS: HashMap<String, String> = get_settings();
}

// extract commenting specific settings from Settings.toml
fn get_settings() -> HashMap<String, String> {
    let mut config = Config::default();
    config.merge(File::new("Settings", FileFormat::Toml)).unwrap();
    let settings = config.try_into::<HashMap<String, String>>().unwrap(); // Deserialize entire file
    settings
}

pub fn config(key: &str) -> String {
    SETTINGS.get(key).unwrap().to_string()
}