0
0
mirror of https://github.com/neon-mmd/websurfx.git synced 2024-11-25 15:38:21 -05:00

feat: add code to parse the new config option (#203)

This commit is contained in:
neon_arch 2023-09-02 20:19:43 +03:00
parent d451fddf49
commit 4eb75a8cb1
2 changed files with 31 additions and 12 deletions

View File

@ -3,7 +3,7 @@
use crate::handler::paths::{file_path, FileType};
use super::parser_models::Style;
use super::parser_models::{AggregatorConfig, RateLimiter, Style};
use log::LevelFilter;
use rlua::Lua;
use std::{collections::HashMap, fs, thread::available_parallelism};
@ -35,17 +35,7 @@ pub struct Config {
pub upstream_search_engines: Vec<crate::engines::engine_models::EngineHandler>,
pub request_timeout: u8,
pub threads: u8,
}
/// Configuration options for the aggregator.
///
/// # Fields
///
/// * `random_delay` - It stores the option to whether enable or disable random delays between
/// requests.
#[derive(Clone)]
pub struct AggregatorConfig {
pub random_delay: bool,
pub rate_limter: RateLimiter,
}
impl Config {
@ -88,6 +78,8 @@ impl Config {
parsed_threads
};
let rate_limter = globals.get::<_,HashMap<String, u8>>("rate_limiter")?;
Ok(Config {
port: globals.get::<_, u16>("port")?,
binding_ip: globals.get::<_, String>("binding_ip")?,
@ -109,6 +101,10 @@ impl Config {
.collect(),
request_timeout: globals.get::<_, u8>("request_timeout")?,
threads,
rate_limter: RateLimiter {
number_of_requests: rate_limter["number_of_requests"],
time_limit: rate_limter["time_limit"],
}
})
})
}

View File

@ -36,3 +36,26 @@ impl Style {
Style { theme, colorscheme }
}
}
/// Configuration options for the aggregator.
///
/// # Fields
///
/// * `random_delay` - It stores the option to whether enable or disable random delays between
/// requests.
#[derive(Clone)]
pub struct AggregatorConfig {
pub random_delay: bool,
}
/// Configuration options for the rate limter middleware.
///
/// # Fields
///
/// * `number_of_requests` -
/// * `time_limit` -
#[derive(Clone)]
pub struct RateLimiter {
pub number_of_requests: u8,
pub time_limit: u8,
}