feat: add config loader to parse json configs

This commit is contained in:
Alex Wellnitz 2024-02-18 18:40:11 +01:00
parent 41824bd04b
commit fc772f4b6a
5 changed files with 27 additions and 0 deletions

16
src/config/loader.rs Normal file
View File

@ -0,0 +1,16 @@
use crate::types::config::{self, Config};
pub fn load_config(config_path: &str) -> Config {
let settings: Config = config::Config::new();
match config::Config::load_from_file(config_path) {
Ok(config) => {
return config;
}
Err(e) => {
eprintln!("Error loading config file: {}", e);
}
}
return settings;
}

1
src/config/mod.rs Normal file
View File

@ -0,0 +1 @@
pub mod loader;

View File

@ -1,4 +1,5 @@
pub mod cmd;
pub mod config;
pub mod handlers;
pub mod search;
pub mod types;

View File

@ -13,13 +13,16 @@ use rustysearch::{
#[actix_web::main]
async fn main() -> std::io::Result<()> {
// Get Command Line Arguments
let args = Args::parse();
// Initialize logger
env_logger::init_from_env(Env::default().default_filter_or("debug"));
// Initialize the search engine
let search_engine = SearchEngine::new(1.5, 0.75);
// Wrap the search engine in a Mutex and then in an AppState
let app_state = web::Data::new(AppStateWithSearchEngine {
search_engine: Mutex::new(search_engine.clone()),
});

View File

@ -1,3 +1,5 @@
use std::fmt::Error;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
@ -13,4 +15,8 @@ impl Config {
database_path: String::from("/tmp/rustysearch.db"),
}
}
pub(crate) fn load_from_file(config_path: &str) -> Result<Config, Error> {
unimplemented!();
}
}