mirror of
https://github.com/neon-mmd/websurfx.git
synced 2024-11-22 14:08:23 -05:00
parent
5f1a43976f
commit
e4476aae28
@ -5,7 +5,7 @@ use crate::handler::paths::{file_path, FileType};
|
|||||||
|
|
||||||
use super::parser_models::Style;
|
use super::parser_models::Style;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use rlua::Lua;
|
use mlua::Lua;
|
||||||
use std::{collections::HashMap, fs, thread::available_parallelism};
|
use std::{collections::HashMap, fs, thread::available_parallelism};
|
||||||
|
|
||||||
/// A named struct which stores the parsed config file options.
|
/// A named struct which stores the parsed config file options.
|
||||||
@ -63,11 +63,10 @@ impl Config {
|
|||||||
/// or io error if the config.lua file doesn't exists otherwise it returns a newly constructed
|
/// or io error if the config.lua file doesn't exists otherwise it returns a newly constructed
|
||||||
/// Config struct with all the parsed config options from the parsed config file.
|
/// Config struct with all the parsed config options from the parsed config file.
|
||||||
pub fn parse(logging_initialized: bool) -> Result<Self, Box<dyn std::error::Error>> {
|
pub fn parse(logging_initialized: bool) -> Result<Self, Box<dyn std::error::Error>> {
|
||||||
Lua::new().context(|context| -> Result<Self, Box<dyn std::error::Error>> {
|
let lua = Lua::new();
|
||||||
let globals = context.globals();
|
let globals = lua.globals();
|
||||||
|
|
||||||
context
|
lua.load(&fs::read_to_string(file_path(FileType::Config)?)?)
|
||||||
.load(&fs::read_to_string(file_path(FileType::Config)?)?)
|
|
||||||
.exec()?;
|
.exec()?;
|
||||||
|
|
||||||
let parsed_threads: u8 = globals.get::<_, u8>("threads")?;
|
let parsed_threads: u8 = globals.get::<_, u8>("threads")?;
|
||||||
@ -81,7 +80,9 @@ impl Config {
|
|||||||
|
|
||||||
let threads: u8 = if parsed_threads == 0 {
|
let threads: u8 = if parsed_threads == 0 {
|
||||||
let total_num_of_threads: usize = available_parallelism()?.get() / 2;
|
let total_num_of_threads: usize = available_parallelism()?.get() / 2;
|
||||||
log::error!("Config Error: The value of `threads` option should be a non zero positive integer");
|
log::error!(
|
||||||
|
"Config Error: The value of `threads` option should be a non zero positive integer"
|
||||||
|
);
|
||||||
log::error!("Falling back to using {} threads", total_num_of_threads);
|
log::error!("Falling back to using {} threads", total_num_of_threads);
|
||||||
total_num_of_threads as u8
|
total_num_of_threads as u8
|
||||||
} else {
|
} else {
|
||||||
@ -110,7 +111,6 @@ impl Config {
|
|||||||
request_timeout: globals.get::<_, u8>("request_timeout")?,
|
request_timeout: globals.get::<_, u8>("request_timeout")?,
|
||||||
threads,
|
threads,
|
||||||
})
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user