From 37e650eb8ac131ae0073bcab121039ffcfb619b9 Mon Sep 17 00:00:00 2001 From: neon_arch Date: Sat, 2 Sep 2023 17:42:55 +0300 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20code=20to=20parse=20t?= =?UTF-8?q?he=20new=20config=20option=20(#201)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config/parser.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/config/parser.rs b/src/config/parser.rs index 4639013..e621bc7 100644 --- a/src/config/parser.rs +++ b/src/config/parser.rs @@ -35,6 +35,7 @@ pub struct Config { pub upstream_search_engines: Vec, pub request_timeout: u8, pub threads: u8, + pub safe_search: u8, } /// Configuration options for the aggregator. @@ -88,6 +89,16 @@ impl Config { parsed_threads }; + let parsed_safe_search:u8 = globals.get::<_,u8>("safe_search")?; + let safe_search: u8 = match parsed_safe_search { + 0..=4 => parsed_safe_search, + _ => { + log::error!("Config Error: The value of `safe_search` option should be a non zero positive integer from 0 to 4."); + log::error!("Falling back to using the value `1` for the option"); + 1 + } + }; + Ok(Config { port: globals.get::<_, u16>("port")?, binding_ip: globals.get::<_, String>("binding_ip")?, @@ -109,6 +120,7 @@ impl Config { .collect(), request_timeout: globals.get::<_, u8>("request_timeout")?, threads, + safe_search }) }) }