feat: add config loader to parse json configs
This commit is contained in:
parent
41824bd04b
commit
fc772f4b6a
16
src/config/loader.rs
Normal file
16
src/config/loader.rs
Normal 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
1
src/config/mod.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
pub mod loader;
|
@ -1,4 +1,5 @@
|
|||||||
pub mod cmd;
|
pub mod cmd;
|
||||||
|
pub mod config;
|
||||||
pub mod handlers;
|
pub mod handlers;
|
||||||
pub mod search;
|
pub mod search;
|
||||||
pub mod types;
|
pub mod types;
|
||||||
|
@ -13,13 +13,16 @@ use rustysearch::{
|
|||||||
|
|
||||||
#[actix_web::main]
|
#[actix_web::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
|
// Get Command Line Arguments
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
// Initialize logger
|
// Initialize logger
|
||||||
env_logger::init_from_env(Env::default().default_filter_or("debug"));
|
env_logger::init_from_env(Env::default().default_filter_or("debug"));
|
||||||
|
|
||||||
|
// Initialize the search engine
|
||||||
let search_engine = SearchEngine::new(1.5, 0.75);
|
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 {
|
let app_state = web::Data::new(AppStateWithSearchEngine {
|
||||||
search_engine: Mutex::new(search_engine.clone()),
|
search_engine: Mutex::new(search_engine.clone()),
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
use std::fmt::Error;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@ -13,4 +15,8 @@ impl Config {
|
|||||||
database_path: String::from("/tmp/rustysearch.db"),
|
database_path: String::from("/tmp/rustysearch.db"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) fn load_from_file(config_path: &str) -> Result<Config, Error> {
|
||||||
|
unimplemented!();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user