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
32
33
34
35
36
37
38
39
// lib.rs
// application related functions are implemented here

use std::collections::HashMap;
use lazy_static::*;
use config::{Config, File, FileFormat, Environment};
use tera::{Tera, compile_templates};

mod db;
pub mod log;
pub mod registration;
pub mod login;
pub mod messages;
pub mod utils;
pub mod app_server;

// Initialize Tera template and Config settings
lazy_static!{
    pub static ref TERA: Tera = compile_templates!("templates/**/*");

    // pull-in app specific settings from Settings.toml and
    // Environment variables that start with APP, eg: APP_DEBUG=1
    static ref SETTINGS: HashMap<String, String> = {
        let mut config = Config::default();
        config.merge(File::new("Settings", FileFormat::Toml)).unwrap();
        config.merge(Environment::with_prefix("APP")).unwrap();
        let settings = config.try_into::<HashMap<String, String>>().unwrap(); // Deserialize entire file
        settings
    };
    pub static ref PAIR_SEPARATOR: char = SETTINGS.get("pair_separator").unwrap().chars().next().unwrap();
    pub static ref VALUE_SEPARATOR: char = SETTINGS.get("value_separator").unwrap().chars().next().unwrap();
}

pub fn app_config(key: &str) -> String {
    let app_config: String = SETTINGS.get(key).unwrap().to_string();
    app_config
}