use std::{collections::HashMap, fs};
#[derive(Clone, Debug, PartialEq)]
pub struct AppProperties {
props_map: HashMap<String, String>,
}
impl AppProperties {
pub fn new() -> Self {
let contents =
fs::read_to_string("app.properties").expect("Couldn't find 'app.properties' file.");
let error_msg =
"Invalid properties file, must be a valid yaml file. Check if there is a space between ':' and property value.";
Self {
props_map: serde_yaml::from_str(contents.as_str()).expect(error_msg),
}
}
pub fn get(&self, key: &str) -> String {
let value = match self.props_map.get(key) {
Some(data) => data,
None => return "".to_string(),
};
value.to_string()
}
}
#[cfg(test)]
mod test;